view+vue上传文件
<Upload ref= "upload"
align="left"
name= "file"
:data="setValidates"
action= '/mysens/sensitiveInformat/ionScan'
:format="['xlsx']"
:before-upload="handleUpload"
:on-success="uploadSuccess"
:on-format-error= "handleFormatError"
:on-error=" uploadError"
:show-upload-list= "false"
v-model="setValidates. plugin_ name"
>
<Button type=" primary" >导入问题列表</Button>
</Upload>
export default {
data (){
return{
setValidates:{
plugin_ name:'',
}
}
},
methods (){
TaskAdd : function (name){
let_ this = this;
this . $refs['setValidates ' ].validate((valid)=>{
if(valid){
this. isLoadingConfirm-true;
this . $refs . upload . post(this. file);
}else{
this. $Message . error( "表单验证失败" )
}
})
},
handleFormatError: function(file){
this . $Message. error(file.name + '文件格式不正确,请上传正确的格式文件!');
}
handleUpload: function(file){
let_ this = this;
this.setValidates.plugin_name = file.name;
this.file = file;
},
uploadSuccess : function(res,file) {
let_ this = this;
console. log("上传成功" ,res, file)
this.isLoadingConfirm = false;
if(res.result == "fail"){
this.$Message.info(res.err_desc);
}else if(res.msg ==成功"){
this.$Message. info( "文件,上传成功")
this.isLoadingConfirm = false,
this.file = null,
this.loading=false ;
}else{
this .$Message.info("文件.上传失败")
}
},
uploadError: function(res, file){
let_ this = this;
console. log(".上传失败”,res, file);
_this.isLoadingList=false;
this.$Message. error("文件上传失败,请重新上传! ")
}
}
}