欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
  1.HTML部分
 
  <inputtype="file"accept='.xls,.xlsx'class="file">
 
  accept属性可以设置要上传文件的格式
 
  2.js部分
 
  接口部分
 
  exportfunctionpostImportRole(params){
 
  returnaxios.post(servers+'/role/import-roles',params,{
 
  headers:{'Content-Type':'multipart/form-data;charset=UTF-8'}
 
  });
 
  }
 
  代码部分
 
  //导入文件
 
  importFile(){
 
  constthat=this;
 
  constformData=newwindow.FormData();
 
  constfiles=document.querySelector("input[type=file]").files;
 
  formData.append("file",files[0]);
 
  if(files.length<=0){
 
  this.$openMessage("请选择导入文件","error");
 
  }else{
 
  if(!/\.(xlsx)$/.test(files[0].name)){
 
  this.$openMessage("导入文件格式不正确","error");
 
  }else{
 
  postImportRole(formData)
 
  .then(res=>{
 
  if(res.data.code==="0"){
 
  that.visibleImportRole=false;
 
  this.$openMessage("导入成功");
 
  this.search();
 
  }else{
 
  this.$openMessage(res.data.msg,"error");
 
  }
 
  })
 
  .catch(()=>
 
  this.$openMessage("导入失败,请核对文档格式是否正确","error")
 
  );
 
  }
 
  }

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h56656.shtml