我正在尝试在我的 Vue 项目中使用一些 Firebase 库(我使用 安装了它npm install firebase)。
我在main.js:
import { Firebase } from 'firebase/app'
import 'firebase/analytics'
import 'firebase/auth'
import 'firebase/messaging'
Firebase.initializeApp({
apiKey: 'xxx',
authDomain: 'xxx',
databaseURL: 'xxx',
projectId: 'xxx',
storageBucket: 'xxx',
messagingSenderId: 'xxx',
appId: 'xxx',
measurementId: 'xxx'
})
Run Code Online (Sandbox Code Playgroud)
我得到:
未捕获的类型错误:无法读取未定义的属性“initializeApp”
这是我的firebase.js
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getAuth } from "firebase/auth";
import { getAnalytics, logEvent, isSupported } from "firebase/analytics";
// Update the config
var firebaseConfig = {
// ...Update config
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const firestore = getFirestore(app);
const auth = getAuth();
const analytics = getAnalytics(app);
// Uncomment the following if you want to use emulator
// if (process.env.NODE_ENV === "development") {
// firestore.useEmulator("localhost", 8080);
// auth.useEmulator("http://localhost:9099"); …Run Code Online (Sandbox Code Playgroud) javascript firebase reactjs google-cloud-firestore react-hooks