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

 

相关文章:

  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
猜你喜欢
  • 2021-07-20
  • 2022-12-23
  • 2022-02-09
  • 2021-10-09
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案