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);
}
})
}
同样的代码 只有一个页面导出不带表头
这个页面带表头
两个是同样的页面 不同路由
有没有可能是接口返回的数据问题
不知道你这个问题是否已经解决, 如果还没有解决的话:新建一个公共的导入页面,即import路由组件 src/views/import/index.vue
在页面中使用前面封装的excel上传组件,并补充导入成功后的回调函数
<template>
<upload-excel :on-success="handleSuccess" />
</template>
<script>
export default {
name: 'Import',
methods: {
handleSuccess({ header, results }) {
console.log(header, results)
}
}
}
</script>
复制代码