html
<el-upload class="avatar-uploader" action="http://yjyhnav1.rdmate.com/ad_admin/" :http-request="upLoad" :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
<img v-if="headUrl" :src="headUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
js
upLoad(file) {
const formData = new FormData();
formData.append('logo', file.file);
formData.append('activity_id', this.activity_id);
console.log(file, "上传的图片");
//发送请求 LOGO(
formData
).then(res => {
// that.imgId = res.data.data
Bus.$emit('logourl', res.data.logo.url)
this.headUrl = res.data.logo.url
}).catch((error) => {
// this.$message.error('头像上传失败,请重新上传!');
})
},
beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg';
const isLt3M = file.size / 1024 / 1024 < 3;
if (!isJPG) {
this.$message.error('上传头像图片只能是 JPG 格式!');
}
if (!isLt3M) {
this.$message.error('上传头像图片大小不能超过 3MB!');
}
return isJPG && isLt3M;
},
handleAvatarSuccess(res, file) {
this.headUrl = URL.createObjectURL(file.raw);
},