Vuejs无法存储子评论

时间:2019-02-08 22:31:16

标签: vue.js vuejs2

我有问题,我的组件CommentManager带有:

        <div v-for="(comment, index) in comments" :key="comment.id">
            <comment @createdChild="addChildren" :data="comment" @deleted="remove(index)"></comment>
        </div>

我使用mixin:

 export default {
  data() {
    return {
      items: [],
      children: [],
   }
},

methods: {
add(item) {
  this.items.unshift(item);

  this.$emit('added');
},

addChildren(children) {
  this.children.push(children);

  this.$emit('addedChildren');
},

remove(index) {
  this.items.splice(index, 1);

  this.$emit('removed');
},

removeChildren(children) {
  this.children.splice(children, 1);

  this.$emit('removedChildren');
},
}
} 

我在组件注释中有一个子注释:

        <div v-for="(comment, index) in children" :key="comment.id">
          <child-comment :data="comment" @deleted="removeChildren(index)"></child-comment>
        </div>

        exports default {
             data() {
               return { children: [] } 
             } 
        }

创建子注释后,我将呼叫:this.$emit('createdChild', response.data);。为什么@createdChild无法正常工作,为什么不能在Comment组件的children中传递新数据? @removedChildren在工作..但是@createdChild无法工作..我没有得到错误

0 个答案:

没有答案