第一种:普通图片路径
uni.downloadFile({
url: this.saveImg, //图片地址
success: function(res) {
const tempFilePath = res.tempFilePath
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: function() {
// 保存成功
},
fail: function(err) {
// 保存失败
}
})
},
fail: function(err){
console.log(err)
}
})
第二种:base64格式的图片
// base64ImgUrl 是你要保存图片的Base64字符串
let saveImg=base64ImgUrl.replace(/^data:image\/\w+;base64,/, "");//去掉data:image/png;base64,
uni.getFileSystemManager().writeFile({
filePath: wx.env.USER_DATA_PATH + '/imageName.png',
data: saveImg,
encoding: &#