对于可能是初学者的错误表示歉意。我搜索了好几天试图找到答案,但无法成功连接到 Firebase 数据库。
所有文件的摘录如下。 我已经安装了 node.js,然后是 firebase init、firebase login,然后是 firebase serve。
无论是在本地托管还是在部署到 firebase 托管后,我都会得到相同的结果。我之前已经尝试过 firebase js 文件的完整路径,同样得到了相同的结果。
我需要做什么才能证明它与 Firebase 的连接正常?
非常非常感谢!
index.html...
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<script src="/__/firebase/4.0.0/firebase-app.js"></script>
<script src="/__/firebase/4.0.0/firebase-auth.js"></script>
<script src="/__/firebase/4.0.0/firebase-database.js"></script>
<script src="/__/firebase/init.js"></script>
<script src="app.js"></script>
<title>Page Title</title>
I'm the header ...
</head>
<body>
I'm the body...
<script> getDatabaseRef() </script>
</body>
</html>
app.js...
function getDatabaseRef(){
console.log('Script called');
var firebaseRef = firebase.Database().ref();
console.log(firebaseRef.ref);
window.alert(firebaseRef);
console.log('Script finished');
}
firebase.json....
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": ".",
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
package.json
{
"name": "jobsheetpoc",
"version": "1.0.0",
"description": "my JS proof of concept",
"main": "app.js",
"dependencies": {
"firebase": "^4.0.0"
},
"devDependencies": {
"firebase-server": "^0.10.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jim",
"license": "ISC",
"keywords": [
"job",
"sheet",
"poc"
]
}
在浏览器中输出...
最佳答案
我有一种奇怪的感觉,你打错了字。您在 firebase.Database
中有一个大写的 Database
而不是普通的 ( firebase.database
)。
关于javascript - firebase.database() 不是函数 - 新的 Firebase 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44151031/