And*_*rea 5 javascript firebase velo
我正在使用的代码如下:
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)
});
}
Run Code Online (Sandbox Code Playgroud)
通过单击按钮来调用 base() 函数,但是代码不起作用,并且不显示控制台日志。
PS:我按照Wix页面成功安装了Firebase和Firestore节点包
我得到的错误如下:
TypeError: firebase.database is not a function
Run Code Online (Sandbox Code Playgroud)
有效的解决方案如下:
<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>
Run Code Online (Sandbox Code Playgroud)
但是我不想使用脚本,因为我更喜欢使用打字稿
wix 论坛中的一位用户似乎提出了一种 hacky 解决方案。
这是它的链接,也许这会对您有所帮助。
https://www.wix.com/corvid/forum/main/comment/5c5a4ffff7055001e2d15cd4
归档时间: |
|
查看次数: |
8435 次 |
最近记录: |