$attrs
和$listeners
爷孙组件传值
情景
A组件内部嵌套B组件,B组件内部嵌套C组件
A组件代码
<div class="grand">
{{count}}父组件
{{msg}}父组件
<child2 :count="count" :msg="msg" @handleCount="handleCount" @handleMsg="handleMsg"></child2>
</div>
data () {
return {
count: 1,
msg: "123"
}
},
methods: {
handleCount (val) {
this.count = val
},
handleMsg (val) {
this.msg = val
}
}
B组件代码