文章评论的回复:多层子传父:子 --> 子 --> 父 可以理解为: 子 --> 父 --> 爷 ,另外说明一点:组件中的props数据,也就是属于当前组件的

69 阅读1分钟

image.png

第一: 在回复这个里的页面comment-item.vue,绑定点击自定义事件,并把参数传递到 上一层 子组件

 @click="$emit('replay-comment',comment)"

image.png

第二:在上comment-list.vue 子组件 监听 第一个绑定的事件:replay-comment,并传递事件对象$event

@replay-comment="$emit('replay-comment',$event)"

image.png

第三: 最后 在父组件中 监听 第二个组件传递过来的事件,定义一个methods 的 onReplay, 接收传过来的参数

image.png

image.png

将数据保存到data中commentReplays,然后将这个数据 传给新的评论子组件,也就是父传子

image.png

在评论回复子props组件接收并

image.png

另外说明一点:组件中的props数据,也就是属于当前组件的数据了,可以拿来传递给其他子组件的用法

image.png