前端用 js-file-download组件下载后端返回的pdf,word,excel文件

后端返回的pdf,word,excel的文件流导出需要让浏览器下载文件

1、安装js-file-download组件

html 复制代码
npm install js-file-download --save

2、在对应的页面引用

html 复制代码
import fileDownload from "js-file-download";

3、在接口返回结果后直接调用即可

html 复制代码
let data={
    id:processId,
    customerId:customerId
}
//后台导出文件接口
feeNotification(data).then(res => {
    //调用fileDownload即可
    fileDownload(res, 'xxxx.xlsx');
})
相关推荐
涛涛ing1 小时前
OpenAI Astra 泄露:零样本生成 3D 网页,前端开发者慌了吗?
前端
ssshooter1 小时前
现在网页都能提供 MCP 了?!
前端·人工智能·程序员
杉氧1 小时前
状态管理变迁史:为什么我们放弃了 Redux 选择 Zustand?
android·前端·react native
cidy_981 小时前
OpenCode 手动配置火山方舟 Agent Plan 教程
前端
鹏多多1 小时前
PC 网站接入微信登录,这 10 个坑我替你踩完了!
前端·javascript·vue.js
律宏阔2 小时前
微信小程序使用 Orval + OpenAPI 自动生成接口:Axios 兼容踩坑记录
前端·微信小程序
律宏阔2 小时前
微信小程序集成 TDesign 完整记录:解决 NPM packages not found
前端·微信小程序
律宏阔2 小时前
微信小程序 ECharts 瘦身实战:分包异步化 + componentPlaceholder 避开主包 2MB 限制
前端·微信小程序
夏天要喝冰可乐2 小时前
从 Idea 到开源插件:我用 Vibe Coding 做了「文章摆渡」
前端·ai编程·vibecoding
小小小小宇2 小时前
pi agent
前端