码迷,mamicode.com
首页 > 其他好文 > 详细

react-native 多页面之间传值

时间:2020-01-06 17:40:56      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:rop   nbsp   需要   nat   reac   传递   state   head   ati   

注:三个页面A,B,C(B页面引入A,C页),A页面中的一个值传递给C页面实现方法

 

B页面代码:

//B页面引入C

<C
                    ref="comRef"
                />
//B页面引入A
<A
                    getImg={(img) => {
                        this.getImg(img)
                    }}
/>
getImg(img) {
         this.refs[‘comRef‘].getHeadImg(img)
    }
 
A页面代码:
在某个方法中触发需要传递的值
this.props.getImg(this.state.headerImg)

C页面代码:
//接收传递过来的值,setState该值
getHeadImg(img){
        this.setState({
            headerImg:img
        })
    }
 

react-native 多页面之间传值

标签:rop   nbsp   需要   nat   reac   传递   state   head   ati   

原文地址:https://www.cnblogs.com/james-L/p/12157450.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!