我正在尝试创建一个社交媒体应用,并在每个帖子上添加评论。
我可以显示评论,但是每个帖子都显示相同的评论集。
我正在努力弄清楚如何在每个帖子上显示不同的评论集。
非常感谢您的帮助!
Github代码here
答案 0 :(得分:0)
我看到了这里的问题:您应该在不同帖子的评论之间添加某种分隔方法。
无分隔:
带分隔符:
为帖子ID添加匹配项,然后将帖子ID添加到每个帖子中。
并使用以下命令在CommentForm.vue中更改脚本:
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);
},
},
};