美文网首页
vue下载execl文件流

vue下载execl文件流

作者: 上海_前端_求内推 | 来源:发表于2021-11-05 17:29 被阅读0次

核心点:1,设置请求头 responseType: 'blob',
2,设置blob type: "application/vnd.ms-excel",type设置可想要下载的文件格式

   //数据导出
    Dataexport() {
      this.$axios
        .get(this.$baseService.VTEExportExcelAsync, {
          params: this.formselect,
          responseType: "blob",
        })
        .then((res) => {
          let a = document.createElement("a");
          const blob = new Blob([res.data], {
            type: "application/vnd.ms-excel",
          });
          let url = window.URL.createObjectURL(blob);
          a.setAttribute("href", url);
          a.setAttribute("download", "测试.xlsx");
          a.click();
        })
        .catch((res) => {
          this.tableLoading = false;
          this.$message.error("网络错误,请联系管理员");
        });
    },

相关文章

网友评论

      本文标题:vue下载execl文件流

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