I am attempting to retrieve all the posts from Firebase and store them in an array but I keep encountering the following error:
Uncaught (in promise) TypeError: Cannot read property 'blogItems' of undefined
Below is the script causing the issue:
export default {
data(){
return{
blogItems: []
}
},
mounted(){
this.getPosts();
},
methods:{
getPosts(){
database.collection('blog').doc('yP6aYXvisFbTsqtQ3MEfuyz6xYE3').collection('posts').get().then(snapshot =>{
const posts = snapshot.docs.map(doc => doc.data())
posts.forEach(function(post){
this.blogItems.push(post.content)
})
})
},
}