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, '失败');
			        }
			    });
			}
相关推荐
刘发财3 小时前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github
牛奶5 小时前
2026年大模型怎么选?前端人实用对比
前端·人工智能·ai编程
牛奶5 小时前
前端人为什么要学AI?
前端·人工智能·ai编程
Kagol8 小时前
🎉OpenTiny NEXT-SDK 重磅发布:四步把你的前端应用变成智能应用!
前端·开源·agent
GIS之路9 小时前
ArcGIS Pro 中的 notebook 初识
前端
JavaGuide9 小时前
7 道 RAG 基础概念知识点/面试题总结
前端·后端
ssshooter10 小时前
看完就懂 useSyncExternalStore
前端·javascript·react.js
格砸10 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端
Live0000011 小时前
在鸿蒙中使用 Repeat 渲染嵌套列表,修改内层列表的一个元素,页面不会更新
前端·javascript·react native
柳杉11 小时前
使用Ai从零开发智慧水利态势感知大屏(开源)
前端·javascript·数据可视化