元素绑定属性需要为自定义属性添加前缀data-xxx,
如<Button type="danger" data-index={index} onClick={this.delToDo}>删除</Button>
绑定监听函数时使用 e.target即可获取对应属性上的值
delToDo=(e)=>{
const action={
type:'DEL_TODO',
value:e.target.getAttribute('data-index')
}
store.dispatch(action)
// console.log(e.target.getAttribute('data-index'))
}
React组件元素绑定属性
最新推荐文章于 2021-07-13 23:56:24 发布