Vue + Ts导出后端post请求传出的excel文件流
const exportAll = ({}) => {
ExcelAPI.yyownload
.post({})
.then(res => {
const content = res.data;
const blob = new Blob([content], { type: "application/vnd.ms-excel" });
const href = URL.createObjectURL(blob);
const a = document.createElement("a");
a.style.display = "none";
a.href = href;
a.download = "运营报表" + now() + ".xls";
a.click();
URL.revokeObjectURL(a.href);
})
.catch(err => {
console.error(err);
})
.finally(() => {});
};
<el-button type="success" @click="exportAll">导出Excel文件</el-button>