1. 在事件处理函数中 直接使用bind绑定this并传参
bind的作用–为前面的函数修改函数内部的this指向 让函数内部的this指向bind参数列表中的第一个参数
第一个参数是修改this指向 this后面参数都会当作参数传递进去
<input onClick={this.changeMsg.bind(this)} />
2. 在构造函数中绑定并传参
当一个函数 调用bind改变了this指向后 bind函数调用的结果有一个返回值 这个值就是被改变this指向后的函数的引用
bind不会修改原函数的this指向
constructor(props){
super(props)
this.state={
}
this.changeMsg = this.changeMsg.bind(this)
}
3. 通过箭头函数
<input onClick={()=>this.changeMsg('此处可以传递参数')} />