<el-upload action="#" :http-request="requestUpload" :show-file-list="false"
:before-upload="(file) => beforeUpload(file, '11')">
<img v-if="ruleForm.businessLicensePhotoFile" :src="ruleForm.businessLicensePhotoFile"
class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
一. 覆盖默认上传事件
我们要 加上
action="#" :http-request="requestUpload"
这样他就不会请求
二. 获取图片回显
:before-upload="(file) => beforeUpload(file, '11')"
在这个函数当中做操作
beforeUpload(file, name) {
if (file.type.indexOf("image/") == -1) {
this.$modal.msgError("文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。");
} else {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
this.ruleForm[name] = reader.result;
};
}
},