- 在父组件中写下代码:
onRef = (ref) => {
this.child = ref
};
2.将此方法传给子组件:
<DoctorTeamIndex onRef={
(ref) => this.onRef(ref)}/>
3.在子组件中的代码
componentDidMount() {
this.props.onRef(this);
}
- 在父组件中调用子组件的某个函数
//getDoctorTeamList是我的方法 你自己写自己的方法
this.child.getDoctorTeamList()