1.通過bind進行傳值
this.函數名.bind(this,參數)
傳遞參數
<button onClick={this.changeNum.bind(this, key, 1)}>+</button>
定義函數
changeNum(index, num) {
// console.log(index,num)
this.state.shopList[index].num += num;
this.setState({
shopList: this.state.shopList
})
}
2.通過es6的方式進行傳值
傳遞參數
<button onClick={()=> this.bind(key) }>刪除</button>
定義函數
//刪除數據
delect = (index)=> {
//刪除數據
this.state.shopList.splice(index,1)
this.setState({
shopList: this.state.shopList
})
}