我正在尝试向我的州添加新数据并将其提供给我的View。但我得到这种错误“TypeError:state.Posts.push不是一个函数”
有人知道为什么我不能将新数据推送到我的'Posts'数组?
Vue方法如下所示:
CreateNewPost () {
const PostData = {
title: this.title,
description: this.description,
image: this.image
}
this.$store.dispatch('CreatePost', PostData)
}
我的行动:
commit('CREATE_POST', {
...Postdata,
imgURL: imgURL
})
State + Getters + Mutation
state: {
Posts: []
},
getters: {
Posts: state => state.Posts
},
mutations: {
CREATE_POST (state, cPost) {
state.Posts.push(cPost)
}
}