//上传图片
<el-upload action=""
ref="uploadImg"
:show-file-list="false"
:auto-upload="false"
:limit=1
:on-change="handleAvatarSuccess">
<img :src="dialogImageUrl"/>
<el-button class="upload_btn">上传图片</el-button>
</el-upload>
handleAvatarSuccess(file) {
let fileType = file.raw.type,
fileSize = file.size / 1024 / 1024,
typeFlag = false,
sizeFlag = false;
if (fileType === 'image/jpeg' || fileType === 'image/png') {
typeFlag = true;
} else {
this.$alert('照片只能上传jpeg、png格式', '提示', {
confirmButtonText: '确定'
});
this.$refs.uploadImg.clearFiles();
}
if (fileSize < 10) {
sizeFlag = true;
} else {
this.$alert('上传头像图片大小不能超过10MB', '提示', {
confirmButtonText: '确定'
});
this.$refs.uploadImg.clearFiles();
}
if (typeFlag && sizeFlag) {
this.dialogImageUrl = URL.createObjectURL(file.raw);
this.personnelFormData.append('file', file.raw);
}
this.$refs.uploadImg.clearFiles();//elementUI 清空搜索条件显示的错误
}
},