vue H5 实现长按图片实现图片保存
YuanTouo 2020-07-08 vue图片保存
由于我的项目用的是mint-ui,需要弹框出现img
<mt-popup
v-model="popupVisible"
popup-transition="popup-fade"
>
<img class="code-img" @touchstart="start" @click="popupVisible=true" :src="imgUrl" alt="">
</mt-popup>
1
2
3
4
5
6
2
3
4
5
6
// 默认数据
data() {
return {
popupVisible:false,
longClick:0,
timeOutEvent:0,
imgUrl:"xxx"
}
},
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
methods: {
// 长按
start() {
var that = this;
this.longClick = 0;
this.timeOutEvent = setTimeout(function() {
that.longClick = 1;
that.downImg()
}, 500);
},
// 下载
downImg() {
if(!window.plus) return;
plus.gallery.save(this.imgUrl, function () {
// alert('保存成功!');
},function(){
// alert('保存失败,请重试!');
});
}
},
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
应该很多朋友会困惑plus是什么?请移步plus对象是啥? plus.gallery?