<el-upload class="avatar-uploader" :action="action" :headers="myHeaders" :file-list="fileList"
accept=".png, .jpg, .jpeg" :on-success="handleAvatarSuccess" :before-remove="handleDelete"
:before-upload="beforeAvatarUpload" :limit="1">
<el-button :loading="uploadLoading" size="mini" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png格式</div>
</el-upload>
data() {
return {
myHeaders: { Authorization:token) },
fileList: [],
action:''
form:{
pictureUrl:''
}
};
},
methods:{
handleDelete() {
this.fileList = [];
this.form.pictureUrl = ""
},
handleAvatarSuccess(res, file) {
if (res.code == 200) {
this.fileList.push({
name: res.data,
url: res.data
})
this.form.pictureUrl = res.data;
}
},
beforeAvatarUpload: function (file) {
const isJPEG = file.type === 'image/jpeg';
const isPNG = file.type === 'image/png';
const isPG = (isPNG || isJPEG)
if (!isPG) {
this.$message.error('上传图片只能是 JPG 或 PNG 格式!');
}
return isPG
},
}