微信开发文档有写怎么获取用户头像
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/userProfile.html
<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
<uv-image :src="userInfo?.avatar?userInfo.avatar:'/static/images/people.png'" width="90rpx" height="90rpx" shape="circle"></uv-image>
</button>
uniapp和微信小程序的uploadFile直接传文件路径,后端接收到的是file文件格式
const onChooseAvatar = async (e : any) => {
const { avatarUrl } = e.detail // 临时链接无法长时间使用,会失效
userInfo.value.avatar = avatarUrl
uni.setStorageSync("userInfo", userInfo.value)
uni.uploadFile({
url: import.meta.env.VITE_WX_BASE_API + "/api/appletAccount/avatar", // 后端上传文件的接口
filePath: avatarUrl,
header: {
Authorization: uni.getStorageSync("token")
},
name: 'file',
success: () => {
uni.showToast({
icon: "success",
title: "头像修改成功"
})
},
})
}