實現(xiàn)在uniapp微信小程序中點擊按鈕,保存圖片到本地相冊,具體實現(xiàn)方法:
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
})
}
}
})
}
手機運行:
文章來源:http://www.zghlxwxcb.cn/news/detail-505553.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-505553.html
到了這里,關(guān)于在uniapp微信小程序中保存圖片到本地相冊的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!