我有2个组件: Post
和 Comments
。
在Post组件中,有一个包含3个道具的Comments组件: postId
, numCom
(评论数量)和 comments
(阵列)。
我得到了注释,我使用props传递数组,现在我想在Comments组件中检索数组并将其添加到数据中,以便我可以添加/删除注释等。
这是我的代码 Comments.vue
:
props: ['id', 'numCom', 'comments'],
data: function() {
return {
newMessage: "",
loading: false,
allComments: this.comments,
num: this.numCom,
}
},
但这不起作用。在Vue开发人员工具中我可以看到 comments
道具充满了评论,但是 allComments
数组是空的。
我该怎么办?