网站首页 > 精选文章 正文
1、访问接口加上: responseType: ‘blob’
2、js 方法: 文件下载的方法
/**
* data: 接口返回的数据
* fileName: 文件名称
* 文件名可从头拿:let _fileName = res.headers['content-disposition'].split(';')[1].split('=')[1];
*/
downloadExcel(data, fileName){
let blob = new Blob([data], {type: "application/vnd.ms-excel"});
const downloadElement = document.createElement('a');
const href = window.URL.createObjectURL(blob); // 创建下载的链接
downloadElement.href = href;
downloadElement.download = decodeURI(fileName); // 下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); // 点击下载
document.body.removeChild(downloadElement); // 下载完成移除元素
window.URL.revokeObjectURL(href); // 释放掉blob对象
}
- 上一篇: vue组件的注册
- 下一篇: 好的项目,万物皆可打包,我将Vue项目打包成客户端(模拟钉钉)
猜你喜欢
- 2025-05-27 vue3安装在线构建ckeditor5教程
- 2025-05-27 使用vue3和go搭建网站(附源码)
- 2025-05-27 「干货」Vue+Element前端导入导出Excel
- 2025-05-27 好的项目,万物皆可打包,我将Vue项目打包成客户端(模拟钉钉)
- 2025-05-27 vue组件的注册
- 2025-05-27 我常用的几个 VueUse 最佳组合,推荐给你们
- 2025-05-27 Vue开发环境搭建
- 2025-05-27 基于 Vue 超漂亮Toast提示组件Vue-Toastification
- 05-27vue3安装在线构建ckeditor5教程
- 05-27使用vue3和go搭建网站(附源码)
- 05-27「干货」Vue+Element前端导入导出Excel
- 05-27好的项目,万物皆可打包,我将Vue项目打包成客户端(模拟钉钉)
- 05-27vue下载excel文件方法
- 05-27vue组件的注册
- 05-27我常用的几个 VueUse 最佳组合,推荐给你们
- 05-27Vue开发环境搭建
- 最近发表
- 标签列表
-
- 向日葵无法连接服务器 (32)
- git.exe (33)
- vscode更新 (34)
- dev c (33)
- git ignore命令 (32)
- gitlab提交代码步骤 (37)
- java update (36)
- vue debug (34)
- vue blur (32)
- vscode导入vue项目 (33)
- vue chart (32)
- vue cms (32)
- 大雅数据库 (34)
- 技术迭代 (37)
- 同一局域网 (33)
- github拒绝连接 (33)
- vscode php插件 (32)
- vue注释快捷键 (32)
- linux ssr (33)
- 微端服务器 (35)
- 导航猫 (32)
- 获取当前时间年月日 (33)
- stp软件 (33)
- http下载文件 (33)
- linux bt下载 (33)