我有两个组件:Comments
.
在Post组件中,有一个Comments组件,它有3个props :postId
、numCom
( comments 数)和comments
(数组).
我得到 comments 并用props 传递数组,现在我想在 comments 组件中检索数组并将其添加到数据中,这样我就可以添加/删除 comments 等.
以下是我的Comments.vue
码:
props: ['id', 'numCom', 'comments'],
data: function() {
return {
newMessage: "",
loading: false,
allComments: this.comments,
num: this.numCom,
}
},
但这行不通.在Vue开发者工具中,我可以看到comments
props 中充满了注释,但allComments
数组是空的.
我该怎么办?