React中父组件怎么调用子组件中的函数

  1. 在父组件中写下代码:
    onRef = (ref) => {
    this.child = ref
    };
    2.将此方法传给子组件:
<DoctorTeamIndex onRef={
    
     (ref) => this.onRef(ref)}/>

3.在子组件中的代码

componentDidMount() {
    
    
    this.props.onRef(this);
  }
  1. 在父组件中调用子组件的某个函数

//getDoctorTeamList是我的方法 你自己写自己的方法 
this.child.getDoctorTeamList()

猜你喜欢

转载自blog.csdn.net/weixin_44738158/article/details/123404152