父组件主动获取子组件的数据和方法:
1.调用子组件的时候定义一个ref
<v-header ref="header"></v-header>
2.在父组件里面通过
this.$refs.header.属性
this.$refs.header.方法
子组件主动获取父组件的数据和方法:
this.$parent.数据
this.$parent.方法
例
<div id="home">
<v-header ref="header" > </v-header>
首页组件父页
<button @click="getChildData">获取子组件的数据方法</button>
</div>
getParentData(){
/*
子组件主动获取父组件的数据和方法:
this.$parent.数据
this.$parent.方法
*/
// alert(this.$parent.msg);
//this.$parent.run();
}
getChildData(){
alert(this.$refs.header.msg)
}