首页 > 技术文章 > react 事件绑定传参

xguoz 2020-02-18 10:00 原文

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

 

推荐阅读