1、xhtml代码
长按保存:
<view class="img" catchlongpress=\'baocun\'></view>
2、Js代码
baocun: function (e) {
wx.showModal({
title: \'提示\',
content: \'确定要保存这张图片吗?\',
success: function (res) {
if (res.confirm) {
console.log(\'用户点击确定\')
wx.getImageInfo({
src: \'xxxxxxx\',
success: function (res) {
console.log(res);
var path = res.path;
wx.saveImageToPhotosAlbum({
filePath: path,
success: function (res) {
console.log(\'图片已保存\');
},
fail: function (res) {
console.log(\'保存失败\');
}
})
}
});
} else if (res.cancel) {
console.log(\'用户点击取消\')
}
}
})
},
详情可参考小程序文档
请发表评论