<view class="form" style="justify-content: space-between;">
<view class="title">头像</view>
<view class="" @click="upAvatar">
<u-image width="112upx" height="112upx" :fade="false" shape="circle" :src="avatarUrl" />
</view>
</view>
.form {
font-size: 28upx;
padding-bottom: 40upx;
display: flex;
flex-direction: row;
align-items: center;
color: #666666;
.title {
padding-bottom: 8upx;
width: 150upx;
color: #101010 !important;
}
}
data() {
return {
avatarUrl:"https://n.sinaimg.cn/translate/w600h600/20180213/XBmS-fyrpeie1413683.gif",
}
},
method:{
upAvatar(){
uni.chooseImage({
count: 1,
sizeType: ['original','compressed'],
sourceType: ['album','camera'],
success: res=> {
console.log('上传头像res',res)
uni.uploadFile({
url:"api/common/uploadToAliOss",
fileType:"image",
filePath:res.tempFilePaths[0],
success:res=>{
console.log("上传成功",JSON.parse(res.data))
this.avatarUrl=JSON.parse(res.data).msg
console.log(this.avatarUrl,'this.avatarUrl')
}
})
},
fail:fail=>{
console.log("upAvatar",fail)
this.avatarUrl=""
}
});
},
}
|