当前位置:网站首页>微信小程序保存圖片的方法
微信小程序保存圖片的方法
2022-06-26 04:40:00 【餘白x】
下載(wx.downloadFile) + 保存(wx.saveImageToPhotosAlbum) +授權(wx.openSetting)
// 保存圖片的方法
serve(img) {
wx.showLoading({
title: '加載中...'
});
//wx.downloadFile方法:下載文件資源到本地
wx.downloadFile({
url: img, //圖片地址
success: function (res) {
//wx.saveImageToPhotosAlbum方法:保存圖片到系統相册
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath, //圖片文件路徑
success: function (data) {
wx.hideLoading(); //隱藏 loading 提示框
wx.showToast({
title: '保存成功',
icon: 'none'
})
},
// 接口調用失敗的回調函數
fail: function (err) {
if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
wx.showModal({
title: '提示',
content: '請授權保存到相册',
modalType: false,
success: res => {
if (res.confirm) {
wx.openSetting({
success(settingdata) {
console.log("settingdata", settingdata)
if (settingdata.authSetting['scope.writePhotosAlbum']) {
wx.showToast({
title: '授權成功',
icon: 'none'
})
} else {
wx.showToast({
title: '授權失敗',
icon: 'none'
})
}
},
fail(failData) {
console.log("failData", failData)
},
complete(finishData) {
console.log("finishData", finishData)
}
})
} else if (res.cancel) {
console.log('用戶點擊取消')
}
}
})
}
},
complete(res) {
wx.hideLoading(); //隱藏 loading 提示框
}
})
}
})
},边栏推荐
- Clean up photo SCR virus / iframekill injection removal /iframekill removal photo scr
- Mobile terminal pull-down loading pull-down loading data
- [H5 development] 02 take you to develop H5 list page ~ including query, reset and submission functions
- Review of number theory
- 2.8 learning summary
- CTF PHP audit bypasses filtering learning from topics
- 问题随记 —— pip 换源
- Zhimeng CMS will file a lawsuit against infringing websites
- Nabicat connection: local MySQL & cloud service MySQL and error reporting
- 2022.1.24
猜你喜欢

Your requirements could not be resolved

Yapi cross domain request plug-in installation

Text horizontal alignment attribute text align and element vertical alignment attribute vertical align

Essential foundation of programming - Summary of written interview examination sites - computer network (1) overview

Zhimeng CMS will file a lawsuit against infringing websites

1.16 learning summary
![[geek challenge 2019] rce me](/img/92/978c54fb42391198300c76ae92893d.jpg)
[geek challenge 2019] rce me

NPM installation tutorial

TP5 distinct method paging problem

OSS CDN alicloud configuration method
随机推荐
Laravel pay payment access process
2022.1.23
PHP get mobile number operator
#微信小程序# 在小程序里面退出退出小程序(navigator以及API--wx.exitMiniProgram)
Performance test comparison between PHP framework jsnpp and thinkphp6
Thinkphp6 using kindeditor
1.19 learning summary
Minecraft 1.16.5 biochemical 8 module 1.9 version 1.18 version synchronization
Install cenos in the virtual machine
1064 (42000) error occurred when installing MySQL and modifying root password
Large numbers (C language)
numpy 通用函数
ROS 笔记(07)— 客户端 Client 和服务端 Server 的实现
Navicat connects the pit of shardingsphere sub table and sub library plug-ins
记录一次循环引用的问题
Compiling and installing phpredis extension on MAC
Numpy index and slice
How can the intelligent transformation path of manufacturing enterprises be broken due to talent shortage and high cost?
防撤回测试记录
Use of better scroll