一般有两种方式
第一种
//一定要记得设计responseType:blob,不然下载下来的文件会损坏,导致文件打不开
axios({
url: "XXXXXXXXX",
method: "post",
responseType: "blob",
data:data
}).then((res) => {
const blob = new Blob([res.data], {
type: "application/vnd.ms-excel",
});
const elink = document.createElement("a");
elink.download = "xxxx" + new Date().getTime() + ".xlsx";
elink.style.display = "none";
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
this.$message({
message: "导出成功",
type: "success",
});
});
第二种
//接口地址直接跳过去就能下载了
window.location.href="xxxxxx"