uniapp上传图片时(可选微信头像、相册、拍照)

参考文献:微信小程序登录------头像_onchooseavatar-CSDN博客

html 复制代码
<button open-type="chooseAvatar" @chooseavatar="onChooseAvatar"> </button>

			onChooseAvatar(e) {
			    uni.showLoading({
			        title: '上传中...',
			        mask: true
			    });
			    uni.uploadFile({
			        url: baseUrl.url + "/xihefile/user/file/upload",
			        filePath: e.detail.avatarUrl,
			        name: "file",
			        formData: {},
			        success: (uploadFileRes) => {
			            uni.hideLoading();
			            uni.setStorageSync("avatarUrl", e.detail.avatarUrl);
			            console.log(uploadFileRes, '');
			            let url = JSON.parse(uploadFileRes.data).data;
			            this.avatarUrl = e.detail.avatarUrl;
			            setTimeout(() => {
			               console.log('this.baseURL前缀',this.baseURL)
							// this.actaimg=`${this.baseURL}${url}`  
							console.log('我是转化后的头像',this.actaimg)
							 this.weAvatar = url;
			            })
			            console.log(e.detail.avatarUrl, '成功');
			        },
			        fail: (err) => {
			            uni.hideLoading();
			            uni.showToast({
			                title: '上传失败,请重试',
			                icon: 'none'
			            });
			            console.log(err, '失败');
			        }
			    });
			}
相关推荐
chimpro几秒前
都2025年了还不会flex?一篇文章带你理顺flex!
前端
LeeAt几秒前
AI单词拍照识别移动端项目(一)
前端·react.js·ai编程
Mintopia8 分钟前
三维空间的 “切蛋糕大师”:八叉树的底层奥秘与妙用
前端·javascript·计算机图形学
布兰妮甜20 分钟前
单例模式在前端(JavaScript)中的实现与应用
前端·javascript·单例模式
Mintopia21 分钟前
Three.js 加载模型文件:从二进制到像素的奇幻漂流
前端·javascript·three.js
前端小巷子39 分钟前
跨域问题解决方案:JSONP
前端·javascript·面试
eric*16881 小时前
尚硅谷张天禹老师课程配套笔记
前端·vue.js·笔记·vue·尚硅谷·张天禹·尚硅谷张天禹
程序员爱钓鱼1 小时前
Go语言中的反射机制 — 元编程技巧与注意事项
前端·后端·go
GIS之路1 小时前
GeoTools 结合 OpenLayers 实现属性查询(二)
前端·信息可视化
烛阴2 小时前
一文搞懂 Python 闭包:让你的代码瞬间“高级”起来!
前端·python