首先需要所保存图片的filepath
this.posterFilePath = ''; //图片的filepath地址
// #ifdef H5
let that = this;
uni.downloadFile({
url: this.posterFilePath,
success: (res) => {
var link = document.createElement('a');
link.href = that.posterFilePath;
link.download = 图片名称.png';
link.click();
}
})
// #endif
// #ifndef H5
uni.saveImageToPhotosAlbum({
filePath: this.posterFilePath,
success(res) {
uni.showToast({
title: '已保存到相册',
icon: 'success',
duration: 2000
});
},
});
// #endif