注意:action="#"
<FormItem style="margin-top:25px" label="输入参数" prop="attachment">
<Upload
style="width:70%"
action="#"
v-model="formData.attachment"
:format="['csv']"
:default-file-list="uploadList"
:before-upload="handleBeforeUpload"
:on-remove="removeFile"
:on-format-error="handleFormatError"
>
<Button type="primary" icon="ios-cloud-upload-outline">上传文件</Button>
<p>支持扩展名.csv</p>
</Upload>
</FormItem>
uploadList: [],
handleBeforeUpload (file) { //上传前钩子
let size = file.size / 1024 / 1024
let type = file.name
if(type.includes('.csv') || type.includes('.CSV') ){
if(size <= 10){
this.formData.attachment = file
this.uploadList = [{ //用于表单的已上传文件显示
'name': file.name,
'url': '',
'size': file.size
}]
return false;
}else{
this.$Message.error('只支持10M以内大小的文件,请重新上传');
return false
}
}else{
this.$Message.error('只支持.csv文件类型,请重新上传');
return false
}
},
removeFile(file, fileList){ //移除已上传文件;
this.formData.attachment = ''
this.uploadList = []
},
handleFormatError (file) {
this.$Notice.warning({
title: '文件类型',
desc: '文件类型错误,请选择.csv'
});
},