Vue3 导出文件为excel 代码如下:
export function excel(code,total,name,upInfo) {
axios({
url: "/report/bb/exportExcel",
method: "post",
data: {
csbs: code,
pageIndex: 1,
pageSize: total,
parameterMap: JSON.stringify(deleteKey(upInfo))
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
responseType: "blob"
}).then(res => {
const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });
const fileName = name
if ('download' in document.createElement('a')) { // 不是IE浏览器
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.setAttribute('download', fileName);
document.body.appendChild(link);
link.click();
document.body.removeChild(link); // 下载完成移除元素
window.URL.revokeObjectURL(url); // 释放掉blob对象
} else { // IE 10+
window.navigator.msSaveBlob(blob, fileName);
}
})
}
同样的代码 只有一个页面导出不带表头

这个页面带表头

两个是同样的页面 不同路由