在vue中导出excel表格,这里是先进行请求拿到文件流,再传给new Blob()对象进行下载。
dataTableExcel() {
let data = {};
axios
.post("url", data, {
responseType: "blob",
})
.then((res) => {
var blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
var blob = new Blob([res.data], {type: "application/zip"});
var downloadElement = document.createElement("a");
var href = window.URL.createObjectURL(blob);
downloadElement.href = href;
downloadElement.download = "表格名称.xlsx || 压缩包.zip";
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(href);
});
},