【问题标题】:I cannot connect Firebase Realtime Database in Vue.js我无法在 Vue.js 中连接 Firebase 实时数据库
【发布时间】:2021-11-01 19:41:38
【问题描述】:

我正在尝试连接到 Firebase 实时数据库,但无法连接。

import { initializeApp } from "firebase/app";
// Import the functions you need from the SDKs you need
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
const firebaseConfig = {
  apiKey: "AIzaSyDDQLlluO4FusOQ8ucJvD_svdMJE5dkOlw",
  authDomain: "portfolio-4dd8c.firebaseapp.com",
  databaseURL: "https://portfolio-4dd8c-default-rtdb.europe-west1.firebasedatabase.app",
  projectId: "portfolio-4dd8c",
  storageBucket: "portfolio-4dd8c.appspot.com",
  messagingSenderId: "237808071168",
  appId: "1:237808071168:web:006dc98a6c3272fbd39ee5"
};
 
// Initialize Firebase
const app = initializeApp(firebaseConfig);

我从“firebase”和 app.database() 导入 firebase,但它给了我一个错误(app.database() 不是函数)。我也试过从'firebase/app'导入firebase

当我从 'firebase' 写这个 import firebase 时,终端给我下面的错误:

未找到此依赖项:

  • ./src/main.js 中的火力基地

要安装它,你可以运行: npm install --save firebase 来自 chokidar (C:) 的错误:错误:EBUSY:资源繁忙或锁定,lstat 'C:\DumpStack.log.tmp'

【问题讨论】:

    标签: javascript firebase vue.js firebase-realtime-database vuejs2


    【解决方案1】:

    您需要导入getDatabase 以使用Modular SDK 获取数据库实例:

    import { initializeApp } from "firebase/app"
    import { getDatabase } from "firebase/database"
    
    const app = initializeApp({...config})
    
    const db = getDatabase(app)
    
    export { db }
    

    【讨论】:

    • 非常感谢我的朋友。你能告诉我如何从数据库中获取数据吗?我是 Firebase 的新手
    • @OzanBilgiç documentation 有旧语法和新语法的示例:)
    猜你喜欢
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 2018-08-21
    • 2017-11-02
    相关资源
    最近更新 更多