こんにちは。Vue.jsに関しては全くの初心者です。アドバイスをいただければと思います。
postsというVueの配列にFirestoreから取得してきたデータを入れたいのですがうまくいきません。
下記の方法ではまずいのでしょうか?
Firestoreからデータが取得できていることは確認しました。
Javascript
1 var app = new Vue({ 2 el: '#app', 3 data: { 4 posts: [] 5 }, 6 mounted: function() { 7 firestore.collection("posts").limit(3).get().then(function(querySnapshot) { 8 querySnapshot.forEach(function(doc) { 9 let data = { 10 'id': doc.id, 11 'userImage': doc.data().userImage, 12 'userName': doc.data().username, 13 'postImage': doc.data().postImage 14 } 15 this.data.posts.push(data); 16 }); 17 }); 18 } 19 })
コンソールのエラー表示 index.html:63 Uncaught (in promise) TypeError: Cannot read property 'posts' of undefined
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/09/08 14:21