可以在Nuxt.js应用中初始化Firebase

时间:2018-04-26 16:39:14

标签: firebase nuxt.js

我正在撰写一个包含Nuxt.jsFirebase的网络应用。我需要在哪个文件中初始化Firebase?换句话说,在哪里放置此代码片段?

var config = {
    apiKey: "xxxxxxxxxx",
    authDomain: "xxxxxxxxx.firebaseapp.com",
    databaseURL: "https://xxxxxxxx.firebaseio.com",
    projectId: "xxxxxxxxx",
    storageBucket: "xxxxxxxxxxx.appspot.com",
    messagingSenderId: "xxxxxxxxxx"
};
firebase.initializeApp(config);

1 个答案:

答案 0 :(得分:10)

在文件夹{ "00:00" :[ [{"id":1, time: "00:05"}, {"id":2, time: "00:05"}, {"id":3, time: "00:05"}], [{"id":1, time: "00:15" }], [{"id":1, time: "00:20" }], [{"id":4, time: "00:35" }]] }

中创建文件firebase.js
plugins

在组件中:

import firebase from 'firebase'
import 'firebase/firestore' //if use firestore

if (!firebase.apps.length) {
  firebase.initializeApp({
    apiKey: "xxx",
    authDomain: "xxx,
    databaseURL: "xxx",
    projectId: "xxx",
    storageBucket: "xxx",
    messagingSenderId: "xxx"
  })
}

firebase.firestore().settings({ timestampsInSnapshots: true })

const db = firebase.firestore()
const storage = firebase.storage() //if use storage

export { storage, db }