后端接口返回的Excel的文件流需要导出让浏览器下载文件
一.先安装 js-file-download组件
npm install js-file-download --save
二.在对应使用的页面引用进去
import fileDownload from "js-file-download";
三.在接口返回结果后直接调用即可
// 下载模板
export function importTemplate (data) {
return request({
url: '/product/tradeClass/importTemplate',
method: 'get',
params: data,
responseType: 'arraybuffer', // 指定返回的类型,不写容易文件损坏
})
}
// 下载模板文件
downloadExport() {
importTemplate().then((res )=> {
// 调用 fileDownload 即可
fileDownload(res, "class.xlsx")
})
},
注:记录遇到的问题学习使用,侵权立删