react-native 多页面之间传值
时间:2020-01-06 19:08:35
收藏:0
阅读:174
注:三个页面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页面代码:
C页面代码:
//接收传递过来的值,setState该值
getHeadImg(img){
this.setState({
headerImg:img
})
}
原文:https://www.cnblogs.com/james-L/p/12157450.html
评论(0)