【发布时间】:2019-03-20 21:46:46
【问题描述】:
我使用的代码如下:
import firebase from "firebase"
import firestore from "firestore"
export function base() {
// Initialize Firebase
var config = {
apiKey: "apiExample",
authDomain: "authDomaninExample",
databaseURL: "databaseUrlExample",
projectId: "projectIdExample",
storageBucket: "storageBucketExample",
messagingSenderId: "000000000"
};
firebase.initializeApp(config)
var db = firebase.firestore(); // This line breaks the code
db.settings({ timestampsInSnapshots: true })
db.collection("Users")
.add({
test: "Test"
}).then(function (docRef) {
console.log("Document written")
}).catch(function (error) {
console.log("Error is: " + error)
});
}
通过单击按钮调用 base() 函数,但是代码不起作用,并且没有显示控制台日志。
PS:我根据Wix页面成功安装了Firebase和Firestore节点包
我得到的错误如下:
TypeError: firebase.database is not a function
有效的解决方案如下:
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase-database.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "apiExample",
authDomain: "authDomaninExample",
databaseURL: "databaseUrlExample",
projectId: "projectIdExample",
storageBucket: "storageBucketExample",
messagingSenderId: "000000000"
};
firebase.initializeApp(config)
var db = firebase.firestore(); // This line breaks the code
db.settings({ timestampsInSnapshots: true })
db.collection("Users")
.add({
test: "Test"
}).then(function (docRef) {
console.log("Document written")
}).catch(function (error) {
console.log("Error is: " + error)
});
</script>
但是我不想使用脚本,因为我更喜欢使用打字稿
【问题讨论】:
-
我想你不能wix.com/code/home/forum/community-discussion/…也许你在你的电脑上安装了这些包
-
这是一个旧答案......新的说这实际上是可能的,但是没有正确记录
-
你能提供链接吗?并进一步解释“我成功安装了firebase和firestore节点包”是什么意思,请
-
问题已更新
标签: javascript firebase velo