以最外层组件为参考点
//我是一个当前组件(最外层)
<template>
<div>
<child />
</div>
</template>
<script>
import child from "./one";//引入子组件
export default {
provide() {
return {
test:"测试"
};
},
components: {
child
},
};
</script>
//////////////////////////////////////////////////
//子级组件
<template>
<div>
我是一个子组件
<span>{{test}}</span>
<grandson />
</div>
</template>
<script>
import Grandson from "./two"//引入孙子组件
export default {
inject: ['test'],
components: { Grandson }
}
</script>
//////////////////////////////////////////////////
//孙子组件
<template>
<div>
我是一个孙子组件
<span>{{test}}</span>
</div>
</template>
<script>
export default {
inject: ['test'],
}
</script>
测试结果