uniapp 头像回显加换头像
html代码
<u-image width="120" height="130" :src="model.headThumb" @click="cheangeHeadThumb"></u-image>
cheangeHeadThumb函数(所有地方都可以用)
cheangeHeadThumb() {
uni.chooseImage({
success: (chooseImageRes) => {
let tempFilePaths = chooseImageRes.tempFilePaths;
uni.showLoading({
title: '上传中'
})
uni.uploadFile({
url: this.$u.http.config.baseUrl + '/uploadFile/file',
filePath: tempFilePaths[0],
header: {
X_Access_Token: this.vuex_token
},
name: 'file',
success: (uploadFileRes) => {
let data = JSON.parse(uploadFileRes.data)
if (data.code == 200) {
console.log(data.data)
this.model.headThumb = data.data
}else {
this.$refs.uToast.show({
title: data.message,
})
}
uni.hideLoading();
}
});
}
});
},