子組件主動獲取父組件的數據和方法:
this.$parent.數據
this.$parent.方法
在子組件Header.vue里面
<template> <div> <h2>我是頭部組件</h2> <button @click="getParentData()">獲取子組件的數據和方法</button> </div> </template> ------------------------------------------------------------------------ <script> export default{ data(){ return{ msg:'子組件的msg' } }, methods:{ run(){ alert('我是子組件的run方法') }, getParentData(){ /* 子組件主動獲取父組件的數據和方法: this.$parent.數據 this.$parent.方法 */ alert(this.$parent.msg);//數據 this.$parent.run(); //方法 } } } </script>