【问题标题】:How to connect Firebase with Wix如何将 Firebase 与 Wix 连接
【发布时间】: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


【解决方案1】:

wix 论坛中的一位用户似乎提出了一个 hacky 解决方案。

这是它的链接,也许这会对你有所帮助。

https://www.wix.com/corvid/forum/main/comment/5c5a4ffff7055001e2d15cd4

【讨论】:

    【解决方案2】:

    这可能会有所帮助“简短的回答是否定的 - Wix Code 仅支持其内部使用的数据库。”

    更多细节 https://www.wix.com/corvid/forum/community-discussion/is-there-a-way-to-connect-to-firebase-database

    【讨论】:

      【解决方案3】:

      公认的解决方案是有问题的,hacky 等同于脆弱。因此,当它破裂时,您可能有一段时间没有意识到它,或者它可能经常破裂。最好的解决方案是使用 wix 和

      使用 wix-router 和 wix-fetch 您可以编写拉取的代码 来自对个人资料页面的传入请求的信息,查询 外部数据库来检索页面的信息,然后 将该数据注入个人资料页面

      https://css-tricks.com/wix-code-database-data-modeling/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-01
        • 1970-01-01
        • 2016-10-08
        • 2020-10-16
        相关资源
        最近更新 更多