firebase.database.ref不是函数错误 [英] firebase.database.ref is not a function error

查看:51
本文介绍了firebase.database.ref不是函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从数据库读取/写入数据,但是我总是会收到此错误:

I am trying to read/write data from my database, but I always get this error:

firebase.database.ref不是函数错误

firebase.database.ref is not a function error

这是我将Firebase纳入项目的方式:

Here is how I have included firebase into a project:

<script src="https://www.gstatic.com/firebasejs/5.9.3/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.3/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.3/firebase-database.js"></script>

然后:

<script>
var config = {
    ...
};

firebase.initializeApp(config);
</script>

Firebase身份验证正常工作.但是当我这样做时:

The Firebase Auth works correctly. But when I do this:

function insertUser(user,name) {


     var ref = firebase.database.ref();

        ref.collection("users").doc(user.uid).set({
         uid: user.uid,
         email: user.email,
         name: name

         })
    .then(function() {
      console.log("Document successfully written!");
    })
    .catch(function(error) {
        console.error("Error writing document: ", error);
    });

}

我在上面遇到错误.我在做什么错了?

I get error above. What am I doing wrong?

推荐答案

database()是一种方法,因此请将其更改为以下内容:

database() is a method so change it to the following:

 var reference =  firebase.database().ref();

最好不要使用相同的变量和方法名称.

Also better not to have same variable and method name.

这篇关于firebase.database.ref不是函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆