// 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));
},
vue axios实现导入导出
于 2021-05-06 07:28:36 首次发布