React事件绑定有主要有三种方式
第一种官方推荐方式:
class
LoginControl
extends
React.Component {
constructor(props) {
super
(props);
this
.handleLoginClick =
this
.handleLoginClick.bind(
this
);
}
}
第二种官方简写方式:
return
(
<button onClick={
this
.handleClick.bind(
this
)}>ES6方式创建的组件</button>
);
第三种箭头函数方式:是我个人比较喜欢的方式
return
(
<button onClick={e =>
this
.handleClick(e
)}>ES6方式创建的组件</button>
);