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, '失败');
			        }
			    });
			}
相关推荐
狂团商城小师妹20 分钟前
XYlease租赁商城小程序
微信·微信小程序·小程序
岁月宁静1 小时前
深度定制:在 Vue 3.5 应用中集成流式 AI 写作助手的实践
前端·vue.js·人工智能
2501_915909062 小时前
“绑定 HTTPS” 的工程全流程 从证书配置到真机验证与故障排查
网络协议·http·ios·小程序·https·uni-app·iphone
心易行者2 小时前
10天!前端用coze,后端用Trae IDE+Claude Code从0开始构建到平台上线
前端
saadiya~2 小时前
ECharts 实时数据平滑更新实践(含 WebSocket 模拟)
前端·javascript·echarts
fruge2 小时前
前端三驾马车(HTML/CSS/JS)核心概念深度解析
前端·css·html
百锦再2 小时前
Vue Scoped样式混淆问题详解与解决方案
java·前端·javascript·数据库·vue.js·学习·.net
烛阴2 小时前
Lua 模块的完整入门指南
前端·lua
2501_915918413 小时前
iOS 混淆实战 多工具组合完成 IPA 混淆、加固与工程化落地(iOS混淆|IPA加固|无源码混淆|Ipa Guard|Swift Shield)
android·ios·小程序·https·uni-app·iphone·webview
浪里行舟3 小时前
国产OCR双雄对决?PaddleOCR-VL与DeepSeek-OCR全面解析
前端·后端