盖州网站优化,frontpage2003网页制作教程,校园网站建设需要哪些,茶叶公司网站源码使用uniapp完成微信小程序的图片下载到本机 话不多说直接上代码吧 话不多说直接上代码吧
使用的vue3的语法糖进行完成的
因为我是请求的后端接口
templateview classloadview classselectPartSelect/Selecttemplateview classloadview classselectPartSelect/Select/viewview classPhotoPartimage :srcimage mode/image/viewview classbtnPartbutton classbtnOneimage src../../static/images/mo.png mode/imagetext更像我/text/buttonbutton classbtnTwo clickdownloadPhoto下载 4.8/button/view/view
/templatescript setupimport { ref, watch, computed, onMounted } from vueimport { onLoad } from dcloudio/uni-appimport Select from ../components/select.vueimport { getCreatePhotoList } from ../../api/index.ts// 图片IDconst photoID ref(null)// 图片const image ref()//获取上一个页面路由传递的参数onLoad((option) {photoID.value Number(option.photoID)getImageList()})// 获取生成的照片const getImageList () {const data {id: photoID.value}getCreatePhotoList(data).then((res) {image.value res.data.items[0].file_path})}// 下载图片按钮const downloadPhoto () {uni.downloadFile({url: image.value,success(res) {if (res.statusCode 200) {// 下载成功保存到相册uni.saveImageToPhotosAlbum({filePath: res.tempFilePath,success() {uni.showToast({title: 保存成功,icon: success});},fail() {uni.showToast({title: 保存失败,icon: none});}});} else {uni.showToast({title: 下载失败,icon: none});}},fail() {uni.showToast({title: 下载失败,icon: none});}});};
/script
//样式的话就不给大家啦如果大家需要的话那就在评论区留言吧随时恭候