【发布时间】:2017-03-10 04:13:52
【问题描述】:
new Vuex.Store({
state: {
comments: {
//store comments collection of each article
/* articleId: [...commentsCollection] */
},
articles: {
ids: [],
collection: []
}
},
mutations: {
//add a comment to comments collection of an article
ADD_COMMENT(state, comment){
state.comments[comment.articleId].push(comment);
//I'm not sure if below line is needed (it works without it tho)
Vue.set(state.comments, comment.articleId, state.comments[comment.articleId]);
}
}
});
- 我的第一个问题是如何在不使用 Vue.set 的情况下改变对象(此处)?
其次,当我们用
comments(){ return this.$store.comments[this.articleId]; }这样的计算属性观察每篇文章中的cmets 时,当我们更新特定文章的cmets 的comments状态时,其他文章的cmets 是否也会更新?如果是这种情况,是不是不好的实施?终于有更好的存储cmets的方法了吗?
谢谢!
【问题讨论】:
-
您尝试第二次时发生了什么?
-
@AmreshVenugopal 计算的工作正常