// 需要在后端提供的post接口处,配置一个responseType来处理二进制文件
method: 'post',
data: params,
responseType: 'blob'
// 表格导出
export function commonExportExcel(response) {
var fileName = decodeURIComponent(
response.headers["content-disposition"].split("=")[1]
);
let blob = new Blob([response.data], {
type: "application/vnd.ms-excel",
});
var downloadElement = document.createElement("a");
var href = window.URL.createObjectURL(blob);
downloadElement.href = href;
downloadElement.download = fileName;
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(href);
}
// 具体使用:
postExportAPI(obj).then((res) => {
if (res.status == 200) {
this.$message.success("导出成功!");
commonExportExcel(res);
} else {
this.$message.error("导出失败!");
}
this.exportLoading = false;
});
前端导出表格
最新推荐文章于 2024-08-22 11:06:05 发布