准备
node-xlsx 插件下载
npm install node-xlsx
vue
- 页面请求(excel文件名、表头和表格数据)
// 表头格式
thead: [
{
name: 'enterprise_name',
title: '企业名称'
}, {
name: 'city',
title: '所属地区'
}
]
- 接收二进制文件流并下载
responseType 必须设置为 arraybuffer 或 blob,否则接收文件会出现乱码或文件损坏无法打开的问题
async function fileDownload (params) {
await axios({
url: baseURL + '/base/file/download',
method: 'POST',
responseType: 'arraybuffer', // 接收blob文件的请求返回类型
data: {
config: params.config, //表格表头
excelName: params.excelName,