壹壹得贰ぺ 2024-08-30 08:36 采纳率: 81.1%
浏览 13
已结题

前端下载xlsx表出现的问题

后端给了个接口 要在前端下载xlsx表

    // 导出模板
    exportTemplate() {
      this.$_Api.Mes.Get({
        responseType: "blob",

        url: "MesCheckCardItem/downloadExcel",
      })
        .then(res => {
          console.log(res);
        })
        .catch(err => {
          const url = window.URL.createObjectURL(
            new Blob([err], { type: "application/vnd.ms-excel;charset=utf-8" })
          );
          const link = document.createElement("a");
          link.href = url;
          let fileName = "123" + ".xlsx";
          link.setAttribute("download", fileName);
          document.body.appendChild(link);
          link.click();
        });
    },


但是下载出来的效果是

img

版本

img


应该怎么解决

  • 写回答

2条回答 默认 最新

  • 李公子lm 2024-08-30 11:30
    关注

    下载文件的那段Blob代码不是应该写到then里吗?另外MIME类型application/vnd.ms-excel;charset=utf-8 这是旧的 .xls文件格式,.xlsx文件格式请用

    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月7日
  • 已采纳回答 8月30日
  • 创建了问题 8月30日