firebase.database.ref 不是函数错误 [英] firebase.database.ref is not a function error
本文介绍了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屋!
查看全文