React的onClick函数如何传参

2023-03-13 08:49:45

不能使用(参数A, 参数B)的方式,而是要使用bind

<Button onClick={this.showEdit.bind(this, 'add')}>添加用户</Button>
  showEdit = (type) => {
    console.log(type)  // 这里面的type就是'add'
    this.setState({ modalType: type, modalVisible: true })
  };

通过   bind(this,参数)   的方法就可以在onClick中传参了

  • 作者:__miss__right
  • 原文链接:https://blog.csdn.net/qq_20337865/article/details/81705153
    更新时间:2023-03-13 08:49:45