美文网首页
react-native 父组件调用子组件的方法

react-native 父组件调用子组件的方法

作者: 程序马 | 来源:发表于2019-11-08 10:47 被阅读0次

子组件

componentDidMount() {

        this.props.oneRef(this);

 }

 _showModal=()=>{

        this.setState({ isVisible: true })

    }

父组件

<Child

             oneRef={this.oneRef}

/>

 oneRef=(ref)=>{

        this.waitAudit = ref

    }

<TouchableOpacity

                    style={{ height: 35, paddingRight: 10, paddingLeft: 10 }}

                    onPress={()=>{

                        that.waitAudit && that.waitAudit._showModal()

                    }}

>

 </TouchableOpacity>    

相关文章

网友评论

      本文标题:react-native 父组件调用子组件的方法

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