我具有以下App结构
RegistrationView (holds the data logic like get, post)
- RegistrationForm (holds the form)
-- Registration Radio Component (radio buttons rendered on delivered data from view)
,我希望能够将数据从视图传递到radio组件作为要呈现的道具并与父窗体组件进行交互。这可能吗?
答案 0 :(得分:1)
在这种情况下,您需要使用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()
,它将更改祖父母组件中的数据。