[英]Firebase App named '[DEFAULT]' already exists in Vuex + Nuxt SPA
I used the Vue CLI with the nuxt/starter template. 我使用Vue CLI和nuxt / starter模板。 I created index.js
in the /store
folder with the following contents: 我在/store
文件夹中创建了index.js
,其中包含以下内容:
import Vuex from 'vuex'
import firebase from 'firebase'
import { firebaseMutations } from 'vuexfire'
var db = firebase.initializeApp({
databaseURL: 'https://vuefiredemo.firebaseio.com'
}).database()
var todosRef = db.ref('todos')
const store = new Vuex.Store({
state: {
counter: 0,
todos: todosRef
},
mutations: {
increment (state) {
state.counter++
},
decrement (state) {
state.counter--
},
...firebaseMutations
}
})
export default store
This works, data works until the page is refreshed and server side rendered. 这工作,数据工作,直到页面刷新和服务器端呈现。 Only when SSR I get the following error: 只有当SSR我收到以下错误时:
Nuxt.js Error: [DEFAULT]: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app). Nuxt.js错误:[DEFAULT]:Firebase:名为'[DEFAULT]'的Firebase应用程序已存在(app / duplicate-app)。
Is this because SSR creates one Firebase instance and then the client creates another? 这是因为SSR创建了一个Firebase实例,然后客户端创建了另一个吗?
You could try this: 你可以试试这个:
if (firebase.apps.length === 0) {
firebase.initializeApp({
databaseURL: 'https://vuefiredemo.firebaseio.com'
})
}
export default firebase.database()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.