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

参考官方文档:点击跳转

具体实现:

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);
			}
		});
	}

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

相关推荐
说私域1 小时前
基于AI智能名片链动2+1模式预约服务商城小程序的数据管理与系统集成研究
大数据·人工智能·小程序
说私域3 小时前
用户感知断裂与商业模式颠覆:AI智能名片链动2+1模式S2B2C商城小程序的破局之道
大数据·人工智能·小程序
peachSoda73 小时前
uniapp开发小程序 使用scroll-view时左右滑动切换无法回到最左边的bug解决方案
小程序·uni-app
复园电子3 小时前
在不重构LIMS的前提下,实现合规电子签名:一种可落地的架构与实现思路
服务器·网络·微信
游戏开发爱好者83 小时前
如何在 Windows 环境下测试 iOS App,实时日志,CPU监控
android·ios·小程序·https·uni-app·iphone·webview
计算机毕设指导64 小时前
基于微信小程序的社区医疗服务管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
fengGer的bugs4 小时前
微信小程序版「死了么APP」,它来了
微信小程序·小程序·死了么·死了么app
我的86呢!4 小时前
微信小程序蓝牙配网
微信小程序·小程序
花卷HJ4 小时前
【微信小程序】open-type=“contact“ 客服按钮样式无法设置?隐藏 button + label 触发完美解决
微信小程序·小程序·notepad++
康小庄4 小时前
通过NGINX实现将小程序HTTPS请求转为内部HTTP请求
java·spring boot·nginx·spring·http·小程序