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, '失败');
			        }
			    });
			}
相关推荐
EnCi Zheng20 分钟前
M5-markconv自定义CSS样式指南 [特殊字符]
前端·css·python
kyriewen24 分钟前
你的网页慢,用户不说直接走——前端性能监控教你“读心术”
前端·性能优化·监控
广州华水科技25 分钟前
北斗GNSS变形监测在大坝安全监测中的应用与优势分析
前端
suirosu26 分钟前
痛风高尿酸血症的治疗方法
笔记·其他·微信·新浪微博
前端老石人36 分钟前
前端开发中的 URL 完全指南
开发语言·前端·javascript·css·html
CAE虚拟与现实36 分钟前
五一假期闲来无事,来个前段、后端的说明吧
前端·后端·vtk·three.js·前后端
Sarvartha1 小时前
三目运算符
linux·服务器·前端
晓晨的博客1 小时前
ROS1录制的bag包转换为ROS2格式
前端·chrome
Wect1 小时前
LeetCode 72. 编辑距离:动态规划经典题解
前端·算法·typescript
donecoding1 小时前
别再让 pnpm 跟着 nvm 跑了!独立安装终极指南
前端·node.js·前端工程化