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