在微信小程序中,当用户登录后,可以在页面中展示用户的头像和昵称。目前,微信小程序不允许开发者在未获得用户同意的情况下展示用户的头像和昵称,当需要展示时,应使用微信小程序的头像昵称填写功能。头像昵称填写功能分为头像选择和昵称填写,具体使用方法如下。
<button open-type="chooseAvatar" bindchooseavatar="onChooseAvatar"> <image class="avatar" src="{{avatarUrl}}" /> </button> <input type="nickname" placeholder="请输入昵称" />
onChooseAvatar:function(e){ console.log(e); const {avatarUrl}=e.detail;//获取头像信息的临时路径 this.setData({avatarUrl}); }