【问题标题】:How to link a React Progressive Web App (PWA) to a firebase database?如何将 React Progressive Web App (PWA) 链接到 firebase 数据库?
【发布时间】:2019-10-24 20:43:58
【问题描述】:

到目前为止,我已通过手动更改 firebase 数据库并在我的 PWA 上实时显示出来,成功更新了我的数据。 但现在我希望将数据写入/插入 Firebase 实时数据库并同时显示更改。

我的问题是,我们如何将数据从 React WebApp 推送到 firebase 实时数据库?

【问题讨论】:

    标签: reactjs firebase firebase-realtime-database progressive-web-apps


    【解决方案1】:

    看看this这些是官方文档。

    您需要启动您的应用程序(使用您自己的应用程序数据)

     var config = {
        apiKey: "apiKey",
        authDomain: "projectId.firebaseapp.com",
        databaseURL: "https://databaseName.firebaseio.com",
        storageBucket: "bucket.appspot.com"
      };
      firebase.initializeApp(config);
    
      // Get a reference to the database service
      var database = firebase.database();
    

    然后就可以使用expose sdk方法进行实例化和操作了

    var database = firebase.database();
    var starCountRef = firebase.database().ref('posts/' + postId + '/starCount');
    starCountRef.on('value', function(snapshot) {
      updateStarCount(postElement, snapshot.val());
    });
    
    

    来源:官方文档

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-02
      • 2019-02-14
      • 2019-09-07
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多