1、需求:
长按可以删除评论
2、
在相应的结构中绑定事件
<span onTouchStart={
this.touchStart.bind(this, index)} onTouchEnd={
this.handleTouchEnd}>
注意一定需要在事件结束的时候解除定时事件,防止资源占用浪费。
// 长按事件
handleTouchEnd = () => {
clearTimeout(this.pressTime);
}
touchStart = (index) => {
this.pressTime = setTimeout(() => {
// 你要todo的事
}, '1000');
}