<text class="text" @click="dianji">点击保存</text>
urlImg: 'https://pics4.baidu.com/feed/f9198618367adab4f8e1f0ac29e56f1b8601e4e2.jpeg?token=2533109e8ce6245ef7fb62ccd92f8c1a&s=0090CD32DA7077BD260C71C90300E0A2'
dianji() {
uni.showLoading({
title: '加载中'
});
uni.downloadFile({
url: this.urlImg,
success: (res) => {
console.log(res);
uni.hideLoading();
if (res.errMsg === 'downloadFile:ok') {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath, //图片地址url
success: function() {
uni.showToast({
title: "保存成功",
icon: "none"
});
},
fail: function() {
uni.showToast({
title: "保存失败,请稍后重试",
icon: "none"
});
}
});
}
},
fail: (err) => {
uni.showToast({
title: "失败啦",
icon: "none"
});
}
})
}
小程序图片默认保存到本地手机
最新推荐文章于 2024-04-17 15:03:07 发布