html
<Upload name="userface" style=" cursor: pointer "
:action="ApiTransfer("/User/SetUserFace")"
:data="ApiTransfer("/User/SetUserFace",userFace)"
:show-upload-list="false"
:before-upload="handleBeforeUpload"
:on-success="successfile"
>
<div class="baseInfo">
<span class="tx" >
<img :src="userFace" alt="">
<!-- <img v-else :src="defaultTx"> -->
</span>
</div>
</Upload>
js
handleBeforeUpload (file) {
var names = file.name.toLocaleUpperCase()
if (names.indexOf(".PNG") > 0 || names.indexOf(".JPG") > 0 || names.indexOf(".JPEG") > 0) {
this.userface = file.name
} else {
this.$Message.warning("JPGPNGJPEG")
return false
}
},
successfile(res, file){
console.log("",res)
console.log("",file)
if (res.Success) {
this.$Message.success("")
this.userFace = res.Description
//this.pheiStatus=true
let userInfo=JSON.parse(localStorage.getItem("userInfo"))
userInfo.head=this.userFace
let _userInfo = JSON.stringify(userInfo)
localStorage.setItem("userInfo",_userInfo)
console.log("loca",localStorage.getItem("userInfo"))
// location.reload();
//window.sessionStorage.setItem("headImg", this.userFace)
}else{
this.$Message.error(res.Description)
}
},
Vue.prototype.ApiTransfer = function(apiname, data) {
console.log("url",configUrl)
// false
if (!apiname) {
alert("apiname!")
return
}
if (!data) return baseUrl + apiname
if (!sessionStorage.accessToken)
this.$router.push({
path: "/login"
})
return Object.assign({}, data, {
random: Math.random(),
BridgePlatformName: BridgePlatformName,
ApiName: apiname,
accessToken: localStorage.accessToken,
deviceToken: localStorage.deviceToken
})
}