Vue.js - 道具如何传给孙子
Vue.js - How to pass down props to grandchildren
我的App结构如下
RegistrationView (holds the data logic like get, post)
- RegistrationForm (holds the form)
-- Registration Radio Component (radio buttons rendered on delivered data from view)
并且我希望能够将数据从视图传递到无线电组件作为要呈现的道具并与父表单组件交互。这可能吗?
在这种情况下您需要使用 dependency injection :
可见:
provide: function () {
return {
prop1: this.someData,
someMethod:this.someMethod
}
},
data(){
return{
someData:'some data'
}
},
methods:{
someMethod(){
this.someData='another data'
}
}
在收音机组件中:
inject: ['someData','someMethod']
并像 this.someData
一样使用它,您可以触发 this.someMethod()
,它会更改祖父组件中的数据。
我的App结构如下
RegistrationView (holds the data logic like get, post)
- RegistrationForm (holds the form)
-- Registration Radio Component (radio buttons rendered on delivered data from view)
并且我希望能够将数据从视图传递到无线电组件作为要呈现的道具并与父表单组件交互。这可能吗?
在这种情况下您需要使用 dependency injection :
可见:
provide: function () {
return {
prop1: this.someData,
someMethod:this.someMethod
}
},
data(){
return{
someData:'some data'
}
},
methods:{
someMethod(){
this.someData='another data'
}
}
在收音机组件中:
inject: ['someData','someMethod']
并像 this.someData
一样使用它,您可以触发 this.someMethod()
,它会更改祖父组件中的数据。