vue axios实现导入导出

 // axios导出函数,参数为导出的接口地址
    downloadExcel(exportUrl) {
    
    
      axios({
    
    
        method: "get",
        url: exportUrl,
        headers: {
    
    
          "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
          Authorization: "Bearer " + sessionStorage.getItem("loginToken") || "",
        },
        responseType: "blob",
      })
        .then((res) => {
    
    
          let data = res.data;
          let url = window.URL.createObjectURL(new Blob([data]));
          let link = document.createElement("a");
          link.style.display = "none";
          link.href = url;
          // if(this.item.excalName !== '' && this.item.excalName !== null && this.item.excalName !== undefined) {
    
    
          //   link.setAttribute("download", this.item.excalName);
          // } else {
    
    
          link.setAttribute("download", "客户列表.xls");
          // }
          document.body.appendChild(link);
          link.click();
        })
        .catch((err) => console.log(err));
    },

猜你喜欢

转载自blog.csdn.net/Yun__shen/article/details/116430753