React学习之事件绑定

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>
);
 

 

posted @ 2018-10-09 10:20  狗狗听话  阅读(228)  评论(0编辑  收藏  举报