繁体   English   中英

Vue.js - 如何将道具传给孙辈

[英]Vue.js - How to pass down props to grandchildren

我有以下应用程序结构

RegistrationView (holds the data logic like get, post)
 - RegistrationForm (holds the form)
 -- Registration Radio Component (radio buttons rendered on delivered data from view)

我希望能够将数据从视图传递到无线电组件作为要渲染的道具并与父表单组件交互。 这可能吗?

在这种情况下,您需要使用依赖注入

鉴于:

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() ,它将更改祖父组件中的数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM