1. 获取微信头像
代码如下:
// html代码
<button class="choose-avatar" open-type="chooseAvatar" bindchooseavatar="onChooseAvatar">
<image class="avatar-info mb20" src="{
{info.avatar}}" mode="scaleToFill" catch:tap="getUserInfo" />
</button>
// js代码
onChooseAvatar(e) {
const {
avatarUrl
} = e.detail;
this.setData({
"info.avatar": avatarUrl
});
},
重点讲解:
- 使用
button
标签,且设置属性open-type="chooseAvatar"
- 设置回调函数
bindchooseavatar="onChooseAvatar"
用以获取获取到的头像信息
2. 获取微信昵称
// html代码
<input type="nickname" value="{
{info.name}}" bindinput='inputname' />
// js 代码
inputname(event) {
this.setData({
"info.name": event.detail.value
})
},
重点讲解:
- 使用
intpu
标签,且设置属性type="nickname"
- 设置回调函数
bindinput='inputname'
用以获取获取到的昵称信息