在uniapp微信小程序中保存图片到本地相册

实现在uniapp微信小程序中点击按钮,保存图片到本地相册,具体实现方法:

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
								})
							}
						}
					})
}

手机运行:

猜你喜欢

转载自blog.csdn.net/jayusmazyyolk/article/details/126532923
今日推荐