微信小程序--注册时获取微信头像

参考官方文档:点击跳转

具体实现:

wxml:

html 复制代码
<button class="avatarBtn" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
    <image class="avatar" :src="avatarUrl"></image>
</button>

js:

javascript 复制代码
const defaultAvatarUrl =
'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
const avatarUrl = ref(defaultAvatarUrl)
//图片路径容器
const imgInfo = reactive({
		imgs: ''
	})

// 头像上传事件
	const onChooseAvatar = (e) => {
		console.log(e);
		avatarUrl.value = e.detail.avatarUrl;
		console.log(e.detail.avatarUrl);
		uni.uploadFile({
			url: 'https://xxxx', //仅为示例,非真实的接口地址
			filePath: e.detail.avatarUrl,
			name: 'file',
			formData: {
				'user': 'test'
			},
			success: function(res) {
                   //剥离接口返回路径
				imgInfo.imgs = JSON.parse(res.data)
				console.log(imgInfo.imgs.data.url);
			}
		});
	}

之后根据注册需求适当调整即可 (〃 ̄︶ ̄)人( ̄︶ ̄〃)

相关推荐
数字游民952711 小时前
推荐一个自带流量加成的小程序接口
人工智能·ai·小程序
2501_9159090612 小时前
Charles 抓不到包怎么办?iOS 调试过程中如何判断请求路径
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074712 小时前
iOS和iPadOS文件管理系统全面解析与使用指南
android·ios·小程序·https·uni-app·iphone·webview
2501_9159214317 小时前
iOS App 开发阶段性能优化,观察 CPU、内存和日志变化
android·ios·性能优化·小程序·uni-app·iphone·webview
qq_124987075317 小时前
基于微信小程序的垃圾分类信息系统(源码+论文+部署+安装)
java·前端·spring boot·后端·微信小程序·小程序·计算机毕业设计
qq_124987075317 小时前
基于微信小程序的照片社交平台(源码+论文+部署+安装)
java·大数据·微信小程序·小程序·毕业设计·计算机毕业设计
Focussend智能化营销18 小时前
【无标题】重构增长链路:如何将企业小程序从“成本中心”,改造为“利润中心”?
人工智能·小程序·重构·自动化·内容运营·数字化营销
游戏开发爱好者818 小时前
在 iOS 开发、测试与上架过程中 如何做证书管理
android·ios·小程序·https·uni-app·iphone·webview
计算机毕设指导618 小时前
基于微信小程序的健康管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
计算机毕设指导618 小时前
基于微信小程序的电影评论与推荐社区平台【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea