爷孙组件,孙子组件调用爷爷组件的方法
爷爷组件
<template>
<p>
<child>爷爷组件</child>
</p>
</template>
<script>
import child from '~/components/dam/child';
export default {
components: {
child
},
provide(){
return{
fatherMethod:this.fatherMethod
}
},
methods: {
fatherMethod() {
}
}
};
</script>
孙子组件
<template>
<p>
<button @click="childMethod()">孙子组件</button>
</p>
</template>
<script>
export default {
methods: {
childMethod(){
this.fatherMethod()
}
};
inject:['fatherMethod']
};
</script>