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を使用せずにオブジェクトを変更するにはどうしたらいいですか?
第2に、特定の記事のコメントの状態を更新すると、
comments(){ return this.$store.comments[this.articleId]; }
のような計算されたプロパティを持つ記事のコメントを見ながら、他の記事のコメントも更新されますか?その場合は悪い実装ではないのですか?Vuexを使って動的にコレクションを保存するにはどうしたらいいですか?最後に、コメントを保存する良い方法がありますか?
ありがとう!
2回目に何が起こったのですか? –
@AmreshVenugopalは正常に動作しました – user3211198