美文网首页
接收并下载后端返回的文件

接收并下载后端返回的文件

作者: 安北分享 | 来源:发表于2021-08-05 19:57 被阅读0次
downloadError(){
  console.log('++++++++++++++++++++')
  // this.$http.post('api/exportFailCustomers',this.filCustomers)
  this.$http({
    method:"post",
    url:"api/exportFailCustomers",
    responseType:"blob",
    data:{
     customers: this.filCustomers
      }
  })
  .then(res =>{
    if(res.data.type){
      const blob = new Blob([res.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
      let link = document.createElement("a");
      link.href=URL.createObjectURL(blob);
      link.setAttribute("download","失败数据.xlsx");
      link.click();
      link=null
      this.$Message.success("下载成功");
    }else{
      this.$Message.error("下载失败")
    }
  })
  .catch(err => {
    this.$Message.error("下载失败")
  })

},

相关文章

网友评论

      本文标题:接收并下载后端返回的文件

      本文链接:https://www.haomeiwen.com/subject/vhkvvltx.html