react 事件绑定

方法1、在constructor中使用bind绑定

  this.handleClick = this.handleClick.bind(this)

方法2、公共类字段使用回调

  handleClick = () =>{

   

  }

方法3、在调用函数的地方使用箭头函数

  

<button onClick={(e) => this.handleClick(e)}> Click me </button>

猜你喜欢

转载自www.cnblogs.com/shuhaonb/p/9485900.html