核心点:1,设置请求头 responseType: 'blob',
2,设置blob type: "application/vnd.ms-excel",type设置可想要下载的文件格式
//数据导出
Dataexport() {
this.$axios
.get(this.$baseService.VTEExportExcelAsync, {
params: this.formselect,
responseType: "blob",
})
.then((res) => {
let a = document.createElement("a");
const blob = new Blob([res.data], {
type: "application/vnd.ms-excel",
});
let url = window.URL.createObjectURL(blob);
a.setAttribute("href", url);
a.setAttribute("download", "测试.xlsx");
a.click();
})
.catch((res) => {
this.tableLoading = false;
this.$message.error("网络错误,请联系管理员");
});
},
网友评论