加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react 事件传参

发布时间:2020-12-15 20:26:03 所属栏目:百科 来源:网络整理
导读:在开发react项目时,点击事件需要传参,就有了以下的写法: Button type="primary" size="small" onClick={this.showModal.bind(this,lists[i])}编辑/Button Button type="primary" size="small" onClick={this.showDelete.bind(this,lists[i])}删除/Button

在开发react项目时,点击事件需要传参,就有了以下的写法:

<Button type="primary" size="small" onClick={this.showModal.bind(this,lists[i])}>编辑</Button>
<Button type="primary" size="small" onClick={this.showDelete.bind(this,lists[i])}>删除</Button>

运行时报错:

但,奇怪的是,我两个button都用到了,可是只有一个报错,那我猜测可能是showModal或者showDelete没定义,一查,确实如此。

另: 附带es6中react的绑定办法:

<Button type="primary" size="small" onClick={e => this.showModal(lists[i])}>编辑</Button>
<Button type="primary" size="small" onClick={e => this.showDelete(lists[i])}>删除</Button>

即,箭头函数

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读