1、通过prop
这是常用方法
2、高阶组件
祖孙传值可以使用
祖:provide; 孙:inject
provide 和 inject 绑定并不是可响应的。
祖先:
// 父组件中返回要传给下级的数据
provide () {
return {
reload: this.reload
}
},
methods: {
reload () {
this.isRouterAlive = false
this.$nextTick(() => {
this.isRouterAlive = true
})
}
}
孙子:
export default {
//引用vue reload方法
inject: ['reload'],
components: {...
},