1、React组件中的render函数会自动绑定this,但是如果只组件的自定义方法则不会自动绑定this,需要编码者手动绑定。
class Product extends React.Component {
constructor(props) {
super(props);
this.handleUpVote = this.handleUpVote.bind(this);
}
// Inside `Product`
handleUpVote() {
this.props.onVote(this.props.id);
}
// render func
render() {
return(
<!-- dom -->
)
}
}