vue+element环境下的写法,其它框架也基本一样
主要是将后台返回的数据处理之后下载为.xlsx的文件,再模拟点击下载
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("网络错误!");
});