ref属性 用来给元素引用信息的。
一,父组件主动获取子组件数据和方法
<div>
<counter ref="counter"></counter>
</div>
这是父组件中引用子组件
用# $refs 获取数据和方法并使用
this.$refs.counter.msg
this.$refs.counter.todo()
data(){
return{
msg:'这是子组件数据'
}
},
这是子组件的数据
二,子组件主动获取父组件数据和方法
data(){
return{
msg:'这是父组件数据'
}
},
这是父组data里面的数据
在子组件中用$parent 获取父组件数据和方法
this.msg = this.$parent.msg;
这是子组件