我使用的代码如下:
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>
但是我不想使用脚本,因为我更喜欢使用 typescript
最佳答案
wix 论坛中的一位用户似乎提出了一个 hacky 解决方案。
这是它的链接,也许这会对你有所帮助。
https://www.wix.com/corvid/forum/main/comment/5c5a4ffff7055001e2d15cd4
关于javascript - 如何将 Firebase 与 Wix 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55270674/