axios download Excel through get

 The writing method in the vue+element environment is basically the same for other frameworks

It is mainly to download the data returned from the background as a .xlsx file after processing, and then simulate click to download

      axios({
        method: "get",
        url: "url****",
        responseType: "blob",    // 重点
        headers: {***},
        params: params,
      })
        .then((res) => {
          let url = window.URL.createObjectURL(new Blob([res.data]));
          let link = document.createElement("a");
          link.style.display = "none";
          link.href = url;
          link.setAttribute("download", this.$route.meta.title + ".xlsx");

          document.body.appendChild(link);
          link.click();
        })
        .catch(() => {
          this.$message.error("网络错误!");
        });

 

Guess you like

Origin blog.csdn.net/joyvonlee/article/details/107998339