导出电子表格

 axios({
        url: "/cardGiveBatchEntity/account/template/download",
        method: "get",
        //vue axios(下载文件流)设置返回值类型responseType:‘blob‘
        responseType: "blob", 
      })
        .then((res) => {
          console.log(res);
          //解析文件充blod中解析
          const url = window.URL.createObjectURL(
            new Blob([res.data], { type: "application/vnd.ms-excel" })
          );
          const link = document.createElement("a");
          link.style.display = "none";
          link.href = url;
          link.setAttribute("download", "文件名称.xlsx");
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        })
        .catch((err) => {
          console.log(err);
        });
————————————————
版权声明:本文为CSDN博主「K哇伊」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/caoluotuo/article/details/120575707

  

posted @ 2023-01-31 10:35  zjxgdq  阅读(19)  评论(0编辑  收藏  举报