<el-form-item label="正面照片" prop="Photo">
<el-upload
ref="imag"
class="avatar-uploader"
:action="imag.url"
accept=".jpg,.png"
:headers="headers"
:data="Photo11"
v-model="form.Photo"
:show-file-list="false"
:on-success="Photo1"
:before-upload="beforeAvatarUpload">
<img v-if="Photo1" :src="Photo1" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
//图片上传地址
imag:{
headers: {Authorization: "Bearer " + getToken()},
url: process.env.VUE_APP_BASE_API + "/mer/Image"
},
//携带参数
Photo11:{name:"张三"},
//图片上传之前判断是否符合要求
beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg';
const isPNG = file.type === 'image/png';
// console.log("99",isPNG)
const isLt2M = file.size / 1024 / 1024 < 2;
// console.log("88",!isJPG && !isPNG)
if (!isJPG && ! isPNG) {
this.$message.error('上传头像图片只能是 JPG或者PNG 格式!');
return false;
}
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2MB!');
return false;
}
return isLt2M;
}
//成功
Photo1(res, file) {
this.legalCardFrontPhoto1= URL.createObjectURL(file.raw);
this.form.legalCardFrontPhoto= res;
},
图片上传前端
最新推荐文章于 2023-04-07 15:47:12 发布