美文网首页
react native 父组件调用子组件方法(react通用)

react native 父组件调用子组件方法(react通用)

作者: 扯扯疯 | 来源:发表于2019-10-16 16:56 被阅读0次

class Home extends React.Component {

  componentDidMount(){
    //调用子组件方法
    this._child.testFun()
  }
  render(){
    return 
      <View>
        <Page ref={child => this._child = child}  />
      </View>
    }
}

class Page extends React.Component {

  testFun=()=>{
    alert(1)
  }
  render(){
    return 
      <View>
        <Text>我是子组件噢!<Text>
      </View>
  }
}

相关文章

网友评论

      本文标题:react native 父组件调用子组件方法(react通用)

      本文链接:https://www.haomeiwen.com/subject/nzyumctx.html