I see the problem you have here: you should add some method of separation between comments on different posts.
Example:
Without separation:
- A user > Nice post
- User 2 > This is a cool post
- The 3rd > Wow, cool!
- A user > Nice post
- User 5 > This is a cool post
- The 6th > Wow, cool!
- A user > Nice post
- User 8 > This is a cool post
- The 9th > Wow, cool!
With separation:
- Post 1 > A user > Nice post
- Post 3 > User 2 > This is a cool post
- Post 2 > The 3rd > Wow, cool!
- Post 3 > A user > Nice post
- Post 1 > User 5 > This is a cool post
- Post 2 > The 6th > Wow, cool!
- Post 2 > A user > Nice post
- Post 1 > User 8 > This is a cool post
- Post 3 > The 9th > Wow, cool!
How to fix:
Add a match for a post id, and add the post ids to each post.
And change the script in CommentForm.vue with this:
export default {
data() {
return {
username: null,
comment: null,
post: null,
};
},
name: "CommentForm",
methods: {
onPost() {
let commentContent = {
name: this.username,
comment: this.comment,
post: this.post
};
this.$emit("comment-posted", commentContent),
(this.username = null),
(this.comment = null),
(this.post = null);
},
},
};