Faker的宿敌 2022-01-20 12:54 采纳率: 90.5%
浏览 154
已结题

关于axios流文件下载后文件损坏问题

问题遇到的现象和发生背景

下载表格后文件损坏打不开

问题相关代码,请勿粘贴截图
this.$_axios({
        method: "POST",
        url:'/api/distribution/currentSituationMap/export/deviceData',
        responseType: "blob",
        data:fromdate,
        headers: {
          "Content-Type": "application/json;charset=UTF-8",
        },
      }).then((res) => {
          const blob = new Blob([res], { type: 'application/xlsx' });
        const aElement = document.createElement('a');
        const blobUrl = window.URL.createObjectURL(blob);
        const filename = `${222}.xlsx`;
        aElement.href = blobUrl;
        aElement.download = filename;
        aElement.click();
        window.URL.revokeObjectURL(blobUrl);
      })

运行结果及报错内容

这是后端返回内容

img

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 系统已结题 2月3日
  • 已采纳回答 1月26日
  • 创建了问题 1月20日