后台管理系统一般都有导出Excel表格功能,一般使用Blob类型保存,并使用a链接下载,代码如下:
async exportExcel() {
let res = await this.axios({
url: "person/manager/exportExcel",
method: "post",
responseType: "blob",
data: {
endDt: this.submitForm.time[1],
idCard: this.submitForm.idCard,
personalName: this.submitForm.personalName,
sex: this.submitForm.sex,
size: "",
start: "",
startDt: this.submitForm.time[0],
status: this.submitForm.status,
subject: this.submitForm.subject,
telephone: this.submitForm.telephone,
},
});
const blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
this.saveFile(blob, moment().format("YYYYMMDDHHmmss") + ".xls");
},
saveFile(data, name) {
const blobUrl = window.URL.createObjectURL(data);
const a = document.createElement("a");
a.style.display = "none";
a.download = name;
a.href = blobUrl;
a.click();
},