react 事件绑定传参

心不动则不痛 提交于 2020-02-18 11:50:44

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

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!