1、父组件主动获取子组件的数据和执行子组件的方法
1.1、调用子组件的时候定义一个ref
通过ref 和获取dom节点(获取子组件)
<v-header ref="header"></v-header>
1.2、父组件主动获取子组件数据
当父组件需要调用子组件时则使用this.$refs的数据
this.$refs.子组件的ref.数据
1.3、父组件主动执行子组件方法
this.$refs.子组件的ref.子组件的方法
** 1.4、修改子组件的数据
**
this.$refs.header.属性="###"
this.$refs.header.data()="###"
2、子组件主动获取父组件的数据和执行父组件方法
2.1、子组件主动获取父组件的数据
this.$parent.数据
2.2、子组件主动获取父组件的数据
this.$parent.方法
2.3 、子组件修改父组件的数据
this.$parent.属性="新值";
2.4、用于当子组件需要调用父组件的方法的场景下使用。
this.$emit('事件',参数)