react 事件处理

2019-10-18  本文已影响0人  糕糕AA
<a href="#" onclick="console.log('The link was clicked.'); return false">
     Click me
    </a>
function handleClick(e) {
   e.preventDefault();
   console.log('The link was clicked.');
   }
 handleClick = () => {
    console.log('this is:', this);
 }

  1. 在回调中使用箭头函数:onClick={(e) => this.handleClick(e)}

  2. 在constructor中绑定 this.handleClick = this.handleClick.bind(this);

上一篇下一篇

猜你喜欢

热点阅读