注:三个页面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
})
}