react 事件綁定傳參


react中事件綁定需要用到onClick來綁定點擊事件。

一般直接寫:

  handleSubmitForm  = e => {
    // 方法內處理
  }
          
  // render方法

  <Button onClick={this.handleFunction} >上一步</Button>

當需要傳參時,有兩種寫法,如下:

              handleGuide = (item) => {
          // 內部方法,處理數據
        }


// render 方法
          this.oprateListNew2.map((item,index)=>( <div key={index} onClick={this.handleGuide.bind(this, item)} // 方法1 // onClick={() => this.handleGuide(item)} // 方法2 > <Tag color="#E59104" style={{ position: 'absolute', top: 0,left: 0 }} >{index>4?'待上線':'已上線'}</Tag> <h4 style={{color: '#fff'}}>{item.title}</h4> </div> ))

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM