1,使用$parent方法
//在父組件中
data(){
return{
a:1
}
}
//在子組件中
this.$parent.a++
2,使用 依賴注入 (推薦使用)
//父組件
export default {
name: 'App',
provide(){
return{
say:this.say
}
},
methods:{
say(){
alert("這是父頁面的方法");
}
}
}
//在子組件中
export default {
inject:['say'],
methods:{
recv(){
this.say();
}
}
}