index.js

import React, { Component } from 'react'
import ReactDOM from 'react-dom'

class Bar extends Component {
  constructor() {
    super()
    this.state = {
      list: ['Lilei', 'Hanmeimei', 'Lihua'],
    }
  }
  clickHandler = value => {
    alert(value)
  }
  render() {
    const btns = this.state.list.map((item, index) => {
      return (
        <button key={index} onClick={this.clickHandler.bind(this, item)}>
          {item}
        </button>
      )
    })
    return <div>{btns}</div>
  }
}

ReactDOM.render(<Bar />, document.getElementById('root'))

相关文章:

  • 2022-01-27
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2021-07-23
猜你喜欢
  • 2022-02-23
  • 2021-10-18
  • 2022-02-09
  • 2021-11-08
  • 2022-12-23
  • 2021-11-10
相关资源
相似解决方案