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