vuexfireはどうも思うように動作しないことが多いですね
ですので私の場合は
pluginファイルでグローバルレベルに登録しています。
import
1import firebase from 'firebase/app'
2import 'firebase/firestore'
3
4if(!firebase.apps.length){
5 firebase.initializeApp({
6 apiKey: "",
7 authDomain: "",
8 databaseURL: "",
9 projectId: "",
10 storageBucket: "",
11 messagingSenderId: ""
12 })
13}
14
15const db = firebase.firestore()
16db.settings({ timestampsInSnapshots: true })
17
18export default ({ app, store }, inject) => {
19 app.$db = db
20 store.db = db
21}
22
storeの方はデータのアップデート用
appの方はデータの取得用で
下記のようにasyncDataでデータを取得できます。
async asyncData({app}){
const userList = []
await app.$db.collection('Users').orderBy('age','asc').get()
.then((snap) =>{
snap.forEach(item => {
userList.push(item.data())
})
})
return {
userList: userList
}
}
template html内はこんな感じです。
<template lang="html">
<section class="index">
<h1>index Component</h1>
<ul>
<li v-for="(user, userIndex) in userList" :key="userIndex">
<nuxt-link :to="`/user/${user.name}`">{{user.name}}</nuxt-link>
</li>
</ul>
</section>
</template>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/22 07:08