react中的this

在ES6写法中的react:React.Component创建组件,其成员不会自动绑定this,需要手动绑定。
手动绑定的方法有3种:
onchange(){
console.log("ok!")
}
1)构造函数中完成绑定
constructor(){
super()
this.onchange=this.onchange.band(this);
}
2)可以在调用的时候使用method.bind(this)完成绑定


3)可以使用箭头函数arraw function绑定
{this.onchange();}}>

你可能感兴趣的:(react中的this)