一》 首先配置一下axios的responseType文件格式为blob

// 下载文件处理文件流的配置
let axios2 = axios.create({
  responseType: "blob",
});

二》 生成Excel表   ----- 其中data是请求返回的文件流

 1  // 生成Excel // data是数据
 2     blobDownload(data, name) {
 3       let m = this;
 4       name = name || "111";
 5       var content = data;
 6       // var data = new Blob([content],{type:"application/octet-stream;charset=utf-8"});
 7       var data = new Blob([content], {
 8         type: "application/vnd.ms-excel;charset=utf-8"
 9       });
10       var downloadUrl = window.URL.createObjectURL(data);
11       var anchor = document.createElement("a");
12       anchor.href = downloadUrl;
13       anchor.download = name + ".xls";
14       anchor.click();
15       window.URL.revokeObjectURL(data);
16     },

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2021-12-11
  • 2021-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-11-16
猜你喜欢
  • 2021-10-20
  • 2021-09-22
  • 2022-12-23
  • 2021-05-04
  • 2022-12-23
  • 2022-12-23
  • 2022-01-28
相关资源
相似解决方案