Answer the question
In order to leave comments, you need to log in
Lost __ob__ observer on array from vuex state?
Hello. I am writing an app in vue. I have arrays of objects in my vuex state: posts and comments. Objects from the comments array have a post_id field.
In the component, I define the computed property like this:
computed: {
comments() {
return this.$store.state.comments.filter(comment => comment.post_id === this.postId);
}
}
newComment(state, payload) {
let comment = {...}
state.comments.push(comment);
}
Answer the question
In order to leave comments, you need to log in
return this.$store.state.comments.filter(comment => comment.post_id === this.postId);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question