1、通过 ref

<Child  ref="demo" />   给子组件添加ref属性

  在父组件使用 `this.refs.demo.state.xxx` 来获取子组件state里面的xxx的值
          
  使用 `this.refs.demo.dosomthing()` 来调用子组件的dosomthing()方法

 

2、通过onRef

<Child onRef={(ref)=>this.child=ref} /> 给子组件添加ref属性

在子组件中,
componentDidMount() {
this.props.onRef(this);
}
在父组件中,
this.child.state.xxx //获取
this.child.dosomthing() // 调用

 

相关文章:

  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2021-07-21
  • 2022-12-23
  • 2021-04-09
  • 2022-03-04
相关资源
相似解决方案