久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      React 點擊事件的 bind(this) 傳參問題

      本文為大家介紹 React 中的點擊事件如何傳參。

      問題描述

      先來看一下問題的描述吧。如下圖:

      React 點擊事件的 bind(this) 傳參問題

      那么我該怎么解決這個問題呢?

      以下是 HTML 代碼,clickFunction 是點擊事件函數(shù),thisStatus 是要傳遞的參數(shù):

      <div onClick={this.clickFunction.bind(this, thisStatus)>收</div>

      以下是 React 代碼的函數(shù)接收參數(shù)方式,thisStatus 函數(shù)接受的參數(shù):

      clickFunction(thisStatus, event) {      console.log('thisStatus', thisStatus);  }

      來解決開頭我提出的問題,同樣,看圖片吧。

      React 點擊事件的 bind(this) 傳參問題

      這樣就可以了。

      總結(jié)

      需要通過 bind 方法來綁定參數(shù),第一個參數(shù)指向 this,第二個參數(shù)開始才是事件函數(shù)接收到的參數(shù):

      <button onClick={this.handleClick.bind(this, props0, props1, ...}></button>     handleClick(porps0, props1, ..., event) {      // your code here  }
      • 事件:this.handleclick.bind(this,要傳的參數(shù))
      • 函數(shù):handleclick(傳過來的參數(shù),event)

      原文地址:https://blog.csdn.net/genius_yym/article/details/54135567

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號