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, '失败');
			        }
			    });
			}
相关推荐
胡萝卜术7 小时前
从API调用到手写LRU:力扣146「LRU缓存」的哈希表+双向链表终极进化之路
前端·javascript·面试
科技道人7 小时前
记录 默认置灰/禁用 app ‘Search Engine Selector‘ 的disable按钮
开发语言·前端·javascript
天疆说7 小时前
Zotero Connector 在 Edge 里找不到桌面 Zotero(Linux / Zotero 9.0.6 / Edge 150)
linux·前端·edge
李伟_Li慢慢9 小时前
02-从硬件说起WebGL
前端·three.js
kyriewen10 小时前
看了微软几万人用AI编程的数据——效率涨24%的代价没人提
前端·ai编程·claude
2601_9637713710 小时前
How to Scale Your WordPress Store Traffic in 2026
前端·php·plugin
亿元程序员10 小时前
老板说我的3D箭头游戏用来做试玩太普通了,没人想玩,让我变点花样...
前端
李伟_Li慢慢10 小时前
01-threejs架构原理-课程简介
前端·three.js
_瑞12 小时前
深入理解 iOS 渲染原理
前端·ios
IT_陈寒12 小时前
SpringBoot自动配置失灵?你可能忘了这个关键注解
前端·人工智能·后端