<div @touchstart="start(item)">
<img />
</div>
js:
const plus=window.plus;
data(){
return{
longClick:0,
timeOutEvent:0,
downImgUrl:"",
Loop:0,
}
}
// 长按
start(item) {
this.downImgUrl=item.picture;
let that = this;
this.longClick = 0;
this.timeOutEvent = setTimeout(function() {
that.longClick = 1;
that.downImg()
}, 500);
},
// 下载
downImg() {
if(!plus) return;
plus.gallery.save(this.downImgUrl, function () {
alert('保存成功!');
},function(){
alert('保存失败,请重试!');
});
},
<img alt="" v-for="(item,index) in imgurl" :src="item" @touchstart.prevent="touchin(index)" @touchend.prevent="cleartime(imgurl[index])" >
一定在data里声明Loop =0;不然不管用
500表示触屏时间,可以根据实际情况写,只要达到这个时间就会触发setTimeout里的事件
touchin(index){
var that=this;
this.Loop = setTimeout(function() {
that.Loop = 0;
//执行长按要执行的内容,如弹出菜单
MessageBox.confirm('是否确认删除').then(action => {
that.imgurl.splice(index,1)
})
}, 500);
return false;
},
触屏离开的事件
cleartime(index) {
var that=this;
clearTimeout(this.Loop);
if(that.Loop!=0){
//这里写要执行的内容(尤如onclick事件)
that.previewPicture(index)
}
return false;
},
网友评论