vue axios实现导入导出

时间:2025-02-07 14:53:00
// 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( !== '' && !== null && !== undefined) { // ("download", ); // } else { link.setAttribute("download", "客户列表.xls"); // } document.body.appendChild(link); link.click(); }) .catch((err) => console.log(err)); },