1.将button
组件open-type
属性设置为chooseAvatar
<button open-type="chooseAvatar">获取头像</button>
2.通过bindchooseavatar
事件回调获取头像信息的临时路径
event.detail.avatarUrl
是微信头像的url。- 用event获取的微信头像是临时路径,临时路径是有时效时间的,在实际开发中要将图片上传至服务器。
<button open-type="chooseAvatar" bindchooseavatar="bindchooseavatar">获取头像</button>
bindchooseavatar(event) {
const url = event.detail.avatarUrl;
this.setData({avatarUrl: url,});
console.log(event, event.detail.avatarUrl);
},