Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

react-native 事件的问题?

    uploadImage(a){ 
    .......
    }
    
    onPress={this.uploadImage.bind(this,this.state.avatarSource.uri)

上面这一段是可以的

constructor(props){
super(props);
this.uploadImage = this.uploadImage.bind(this);
}
onPress={this.uploadImage(this.state.avatarSource.uri)}

这么写就报错. 其他不带参数的事件这么写都正常, 这个带参数的哪里不对?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

直接用箭头函数写 onPress={ ()=> this.uploadImage(this.state.avatarSource.uri)}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.6k users

...