当前位置: 首页 > news >正文

记录:导出功能:接收文件流数据进行导出(vue3)

请求接口:一定要加responseType: 'blob'

后端返回数据:

api.js
export function export() {return request({url: 'dev/api/export',method: 'get',responseType: 'blob',//一定要加})
}
vue:
import {export} from '@/api'// 导出
const exportTable = () => {ElMessageBox.confirm('确定导出表格数据?', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',}).then(() => {exportGradeScene().then((res) => {exportFile(res)})}).catch(() => {ElMessage({type: 'info',message: '导出取消',})})
}
const exportFile = (response) => {// 导出文件通用逻辑(仅限axios)const contentDisposition = response.headers['content-disposition'] // 解析文件名const filename = decodeURIComponent(contentDisposition.split('filename=')[1].trim().replace(/\"/g, ''),)// 创建链接并触发下载const url = window.URL.createObjectURL(new Blob([response.data], {type: 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',}),)const link = document.createElement('a')link.href = urllink.setAttribute('download', filename)document.body.appendChild(link)link.click()
}

http://www.lryc.cn/news/516201.html

相关文章:

  • 基于Spring Boot + Vue3实现的在线汽车保养维修预约管理系统源码+文档
  • PHP框架+gatewayworker实现在线1对1聊天--接收消息(7)
  • 18.1、网络安全策略分类 流程 内容
  • 深入理解连接池:从数据库到HTTP的优化之道
  • 【2025最新计算机毕业设计】基于SpringBoot+Vue智慧养老医护系统(高质量源码,提供文档,免费部署到本地)【提供源码+答辩PPT+文档+项目部署】
  • 关于使用vue-cropperjs上传一张图后,再次上传时,裁剪的图片不更新的问题
  • 学习threejs,导入VTK格式的模型
  • 大麦抢票科技狠活
  • PostgreSQL 表达式
  • WPF区域导航+导航参数使用+路由守卫+导航日志
  • Springboot启动报错:Failed to start bean ‘documentationPluginsBootstrapper‘
  • qt-C++笔记之动画框架(Qt Animation Framework)入门
  • C++26 函数契约(Contract)概览
  • Flink CDC 自定义函数处理 SQLServer XML类型数据 映射 doris json字段方案
  • F.interpolate函数
  • 华为交换机---自动备份配置到指定ftp/sftp服务器
  • nginx学习之路-nginx配置https服务器
  • UCAS 24秋网络认证技术 CH10 SSL 复习
  • 【linux内核分析-存储】EXT4源码分析之“文件删除”原理【七万字超长合并版】(源码+关键细节分析)
  • 代码随想录 day62 第十一章 图论part11
  • springboot571基于协同过滤算法的私人诊所管理系统(论文+源码)_kaic
  • Uniapp Android 本地离线打包(详细流程)
  • vite+vue3动态引入资源文件(问题已解决但离了个大谱)
  • 通过 4 种方式快速将音乐从 iPod 传输到 Android
  • ArcGIS中怎么把数据提取到指定范围(裁剪、掩膜提取)
  • 【Vaadin flow 实战】第3讲-快速上手构建VaadinFlow+Springboot的全栈web项目
  • HBase Cassandra的部署和操作
  • 用户界面软件01
  • 【云原生】Docker Compose 从入门到实战使用详解
  • 【ShuQiHere】使用 SCP 进行安全文件传输