修改删除功能,使得点击英雄名称也可以删除。

del = (x) => { const { heroList } = this.state; heroList.splice(x, 1); this.setState({ heroList }); }

render() { const { heroList, name } = this.state; return ( <>

英雄联盟

    {heroList.map((item, index) => (
  • <span onClick={() => this.del(index)}>{item} <button onClick={() => this.del(index)}>删除英雄
  • ))}

  <input type="text" onInput={this.fn} value={name} />
  <button onClick={this.add}>点击添加新英雄</button>
</>

);

标签: 游戏


原文地址: https://www.cveoy.top/t/topic/eSp6 著作权归作者所有。请勿转载和采集!