I try remove post from PostList, but getting an error
<PostList
:posts="sortedAndSearchedPosts"
@remove="removePost"
v-if="!isPostsLoading"
/>
remove post function
removePost(post) {
this.posts = this.posts.filter((p) => p.id !== post.id);
},
posts initialized here
computed: {
...mapState({
posts: (state) => state.post.posts,
}),
...mapGetters({
sortedPosts: "post/sortedPosts",
sortedAndSearchedPosts: "post/sortedAndSearchedPosts",
}),
},
Not clear where this.posts
are actually initially set up.
If I guess your architecture right, I see 2 options for you:
sortedAndSearchedPosts
reflects the change directlyposts
:data () {
return {
posts: [...this.sortedAndSearchedPosts],
...
}
},
and update your code to use the local list of posts:
<PostList
:posts="posts"
...
/>
Hope this helps!