Save pictures to local album in uniapp WeChat applet

Click the button in the uniapp WeChat applet to save the picture to the local album. The specific implementation method:

template

<button class="haibaobtn" @click="handledownload">保存图片</button>

js

handledownload(){
const that = this
					uni.downloadFile({
						url: '图片地址',
						success: res => {
							if (res.statusCode === 200) {
								uni.saveImageToPhotosAlbum({
									filePath: res.tempFilePath,
									success: function() {
										uni.showToast({
											title: '保存成功',
											duration: 2000
										})

									},
									fail: function() {
										uni.showToast({
											title: '保存失败',
											duration: 2000
										})

									}
								})
							} else {
								uni.showToast({
									title: '保存失败',
									duration: 2000
								})
							}
						}
					})
}

The phone runs:

 

Guess you like

Origin blog.csdn.net/jayusmazyyolk/article/details/126532923