Provide/inject provides us with a way to pass values between components, but by default, provide/inject binding is not reactive. In official words:
Then, we can achieve data responsiveness by passing an object.
//父组件Father.vue
data(){
return {
obj: { //一定是个对象,才能实现响应式
name: 'eavan'
}
}
},
provide() { //要访问组件实例 property,我们需要将 provide 转换为返回对象的函数
return{
user: this.obj
}
}
//子组件Child.vue
export default {
name: 'Child',
inject: ['user'] //正常使用inject
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。