uniapp 保存网络图片到手机相册
2020-05-22 本文已影响0人
Allen6879
<view class="green bor_green pad_t_b_4 pad_l_r_10 radius5" @tap="saveHttpImg(currentPayInfo.img)">保存图片</view>
//下载网络图片
saveHttpImg(url){
let _t = this;
uni.downloadFile({
url:url, //仅为示例,并非真实的资源
success: (res) => {
if (res.statusCode === 200) {
let file = res.tempFilePath;
_t.save(file)
}
}
});
},
//保存图片到本地
save(url){
let _this = this;
_this.$util._loading("保存中...");
uni.saveImageToPhotosAlbum({
filePath: url,
success: () => {
uni.hideLoading();
_this.$util._toast("图片已保存");
},
fail: () => {
uni.hideLoading();
_this.$util._toast("保存失败");
},
complete: () => {
}
});
},