(1)在你要长按的盒子《标签》上添加如下代码
@touchstart.prevent="touchstart(index)" @touchend.prevent="touchend"
(2)编写touchstart函数
touchstart(index) {
let that = this;
clearInterval(this.Loop); //再次清空定时器,防止重复注册定时器
console.log(index)
this.Loop = setTimeout(function() {
uni.showModal({
title: '删除',
content: '请问要删除本条消息吗?',
success: function(res) {
if (res.confirm) {
console.log(this.noticeList)
//alert(this.noticeList[index].id)
deleteNotify(that.noticeList[index].id, '0').then(res => {
if (res.data.code == 1) {
uni.showToast({
title: '删除成功',
duration: 2000
})
that.getnotify();
}
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}.bind(this), 1000);
},
(3)编写touchend函数
touchend() {
console.log('结束')
clearInterval(this.Loop);
}