首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JS防火墙数据库错误db.ref不是一个函数

JS防火墙数据库错误db.ref不是一个函数
EN

Stack Overflow用户
提问于 2022-06-13 16:08:14
回答 1查看 608关注 0票数 0

嗨,我正试图在我的网站上实现firebase实时数据库API,我遵循以下文档:https://firebase.google.com/docs/database/admin/save-data#node.js,但是我得到了这个错误:

这是我的密码:

代码语言:javascript
复制
 <script type="module">
    // Import the functions you need from the SDKs you need
    import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js";
    import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.8.3/firebase-analytics.js";
    import { getDatabase } from "https://www.gstatic.com/firebasejs/9.8.3/firebase-database.js";;

    // 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
    // For Firebase JS SDK v7.20.0 and later, measurementId is optional
    const firebaseConfig = {
      apiKey: "xxxxxxxxxxxxxxxxxxxxx",
      authDomain: "xx.x.xxx",
      databaseURL: "xxxxxxxxxxxxxxxx",
      projectId: "xxxxx",
      storageBucket: "xxxxxxxxx",
      messagingSenderId: "xxxx",
      appId: "xxxxx",
      measurementId: "xxxxxxx"
    };

    const fireapp = initializeApp(firebaseConfig);
    const db = getDatabase(fireapp);
    const ref = db.ref('server/saving-data/fireblog');
  </script>

我做错了什么?我使用的版本是否不正确?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-13 16:16:18

您将API的新模块/v9语法与旧的命名空间语法混合在一起,这是行不通的。

在v9中,相当于最后一行的内容是:

代码语言:javascript
复制
const dbref = ref(db, 'server/saving-data/fireblog');

由于您似乎正在使用过时的代码,因此我建议保持文档的方便性(例如,本节介绍获得参考资料),以比较v8和v9代码示例,并阅读升级指南

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72605869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档