微信小程序下载图片到本地
downloadImg: function(e){ //触发函数
console.log(e.currentTarget.dataset.url)
wx.downloadFile({
url: e.currentTarget.dataset.url, //需要下载的图片url
success: function (res) { //成功后的回调函数
wx.saveImageToPhotosAlbum({ //保存到本地
filePath: res.tempFilePath,
success(res) {
wx.showToast({
title: \'保存成功\',
icon: \'success\',
duration: 2000
})
},
fail: function (err) {
if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
wx.openSetting({
success(settingdata) {
console.log(settingdata)
if (settingdata.authSetting[\'scope.writePhotosAlbum\']) {
console.log(\'获取权限成功,给出再次点击图片保存到相册的提示。\')
} else {
console.log(\'获取权限失败,给出不给权限就无法正常使用的提示\')
}
}
})
}
}
})
}
});
},
版权声明:本文为lhj-blog原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。