小程序现在升级了之前的getUserInfo无法拿到用户的头像和昵称,需要单独获取设置 最近项目里面在整改 今天贡献上代码
代码里面头像设置
<!-- #ifdef MP-WEIXIN -->
<button open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
<image style="width: 90rpx;height: 90rpx;border-radius: 50%" :src="avatar?avatar:'../../static/logo.png'"></image>
</button>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<image @click="avatar?goLogin():''" style="width: 90rpx;height: 90rpx;border-radius: 50%" :src="avatar?avatar:'../../static/logo.png'"></image>
<!-- #endif -->
头像上传
onChooseAvatar(e){
console.log(e.detail.avatarUrl)
let that = this;
let token = uni.getStorageSync('token');
uni.showLoading({
title: '上传中...'
});
uni.uploadFile({
// url: config.APIHOST1 + '/alioss/upload', //仅为示例,非真实的接口地址
url:'', //仅为示例,非真实的接口地址
filePath: e.detail.avatarUrl,
header: {
token: token
},
name: 'file',
success: uploadFileRes => {
let url = JSON.parse(uploadFileRes.data).data;
that.$Request.postJson(
'/app/user/updateUserImageUrl?avatar=' + url).then(
res => {
uni.hideLoading();
if (res.code === 0) {
that.$queue.showToast(
"更新成功");
that.getUserInfo();
}
});
}
});
},
设置昵称类型
type="nickname"