箭头函数
handleOpen = (e)=> {
this.setState({
open: true
})
}
<Button color='primary' onClick={this.handleOpen}>打开模态框</Button>
bind
handleOpen(e) {
this.setState({
open: true
})
}
<Button color='primary' onClick={this.handleOpen.bind(this)}>打开模态框</Button>
在构造函数里面 bing
constructor(props){
super(props);
this.handleOpen = this.handleOpen.bind(this);
}
handleOpen(e) {
this.setState({
open: true
})
}
<Button color='primary' onClick={this.handleOpen}>打开模态框</Button>
click添加箭头函数
handleOpen(e) {
this.setState({
open: true
})
}
<Button color='primary' onClick={()=>{this.handleOpen}}>打开模态框</Button>