Warm tip: This article is reproduced from serverfault.com, please click

其他-如何将 Firebase 添加到 Vuepress?

(其他 - How to add firebase to Vuepress?)

发布于 2018-10-29 22:28:21

我正在尝试将 firebase 代码添加到 Vuepress 中,以便我可以将一个简单的评论应用程序嵌入到所有 Vuepress 页面中。想知道如何做到这一点?

``

<script src="https://www.gstatic.com/firebasejs/5.5.6/firebase.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "asdf",
    authDomain: "adsf-9e0b6.firebaseapp.com",
    databaseURL: "https://asdf-9e0b6.firebaseio.com",
    projectId: "sadf-9e0b6",
    storageBucket: "adsf-9e0b6.appspot.com",
    messagingSenderId: "asdf"
  };
  firebase.initializeApp(config);
</script>

``

Questioner
Raja Rao
Viewed
0
Raja Rao 2018-11-03 03:47:42

config.jshead数组中添加类似的内容请注意,这会添加firebase-app(核心)、firebase-authfirestore和 ,cloud functions因为我在我的项目中使用了 4 个模块。

请注意,我还初始化都firebasefirestore这里。因此,我将firestore作为全局变量。

当 firebase 加载时,所有这些都将被提升到应用程序的头部部分。

 head: [

    [
      "script",
      {
        src: "https://www.gstatic.com/firebasejs/5.5.6/firebase-app.js"
      }
    ],

    [
      "script",
      {
        src: "https://www.gstatic.com/firebasejs/5.5.6/firebase-auth.js"
      }
    ],

    [
      "script",
      {
        src: "https://www.gstatic.com/firebasejs/5.5.6/firebase-firestore.js"
      }
    ],

    [
      "script",
      {
        src: "https://www.gstatic.com/firebasejs/5.5.6/firebase-functions.js"
      }
    ],

    [
      "script",
      {},
      `var config = {
        apiKey: "apikey",
        authDomain: "app.firebaseapp.com",
        databaseURL: "https://app.firebaseio.com",
        projectId: "appname",
        storageBucket: "appname.appspot.com",
        messagingSenderId: "12345"
      };
      firebase.initializeApp(config);
      const firestore = firebase.firestore();
      const settings = { /* your settings... */
          timestampsInSnapshots: true
      };
      firestore.settings(settings);`
    ],
    ]