2
我目前正在开发一个web项目。我使用VueJS 2和Vuex 2. 问题是,当我更新我的状态的一个子数组时,状态不绑定到视图。VueJS:Vuex在修改状态后不更新视图
我的状态:
export const state = {
comments: [],
}
和变异:
...
export const mutations = {
ADD_REPLY (state, { id, comment }) {
let c = state.comments.find((c) => c.id === step);
if (c.replies === undefined)
c.replies = [];
c.replies.push(comment);
}
}
...
在本例中,当我推回复(ADD_REPLY),它不是在视图中更新。你有什么主意吗 ?
请参阅https://vuex.vuejs.org/en/mutations.html#mutations-follow-vues-reactivity-rules – Phil
@Phil我试图像这样使用它'Vue.set(c。回复,c.replies.length,评论);'但它不起作用 –
也许尝试'c.replies = c.replies.concat(评论)'。 – Phil