bind绑定
将点击方法函数与onPress绑定在一起
onPress={this.show.bind(this.xx)}
或者在生命周期函数里绑定
constructor(props) {
super(props);
this.test = this.test.bind(this)
}
注意 如果在绑定时不执行bind方法 直接执行onPress={this.show} 则会在ReLoad时直接执行函数
也就是说,没有bind时组件加载时会执行该函数,但是点击操作并不能使函数执行。
箭头函数绑定
onPress={()=>this.show("XX”)}
或者
onPress={this.show}
this.show=()=>{...}