父
class Home extends React.Component {
componentDidMount(){
//调用子组件方法
this._child.testFun()
}
render(){
return
<View>
<Page onRef={child => this._child = child} />
</View>
}
}
子
class Page extends React.Component {
componentDidMount() {
this.props.onRef(this)
}
testFun=()=>{
alert(1)
}
render(){
return
<View>
<Text>我是子组件噢!<Text>
</View>
}
}