<!-- #ifdef MP-WEIXIN -->
<button class="share-button" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
<view>
<image src="{{avatar}}" style="width: 140rpx;height: 140rpx;border-radius: 50%;"/>
</view>
</button>
<!-- #endif -->
onChooseAvatar(e) {
let that = this
const {
avatarUrl
} = e.detail
uni.uploadFile({
url: '后台上传图片接口',
filePath: avatarUrl,
fileType: 'image',
name: 'file',
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
},
formData: {
'upfile': avatarUrl
},
success: (uploadFileRes) => {
let rest = JSON.parse(uploadFileRes.data)
console.log(rest)
},
fail: (error) => {
console.log(error)
},
})
},
/**
* 去掉按钮样式
*/
.share-button {
outline: none;
border: none;
margin: 0;
padding: 0;
background-color: #FFFFFF;
}
.share-button::after {
outline: none;
border: none;
}
Uniapp微信授权头像
最新推荐文章于 2024-03-28 15:24:55 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)