javascript - 如何将 Firebase 与 Wix 连接

标签 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)
        });
}

通过单击按钮调用 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/

相关文章:

javascript - 使用 javascript 过滤输入类型数字

javascript - 多步表单

android - 每个应用程序一个 Firebase google json 配置文件?

ios - Firebase 快速登录不正确

javascript - 如何在wix后端获取/连接数据库字段值

javascript - 是否可以隐藏父元素的父元素的子元素?

javascript - iframe 父 url

javascript - firebaseui.js 未捕获类型错误 : Cannot read property 'call' of undefined

javascript - 在javascript中从api获取数据时如何传递用户名和密码凭据?

使用 Wix 网站构建器的 Javascript