前端

download(){
debugger;
this.loading = true;
axios.post('http://localhost:8081/brand_case/dao.do?method=export',this.queryParams,{
responseType: 'blob'
}).then( res=>{
console.log('res', res)
// var data = res.data.data;
// 截取文件名,这里是后端返回了文件名+后缀,如果没有可以自己拼接
// 切割出文件名
const fileNameEncode = res.headers['content-disposition'].split('filename=')[1]
/// 解码
const fileName = decodeURIComponent(fileNameEncode)
console.log('fileName', fileName)
// 设置type类型
const blob = new Blob([res.data], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; application/octet-stream'
})
const fileUrl = window.URL.createObjectURL(blob)
let a = document.createElement("a");
a.href = fileUrl
console.log('url', fileUrl)
a.setAttribute('download', fileName)
a.style.display = 'none'
a.click()
a.remove()
this.loading = false;
}
)
}
}

后端---模板

package com.itheima.pojo;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor; import java.util.Date; @NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
@HeadRowHeight(value = 30)
@ContentRowHeight(value = 25)
@ColumnWidth(value = 30)
public class UserExcel {
@ExcelProperty(value = "用户编号")
private Integer userId;
@ExcelProperty(value = "姓名")
private String username;
@ExcelProperty(value = "性别")
private String gender;
@ExcelProperty(value = "工资")
private Double salary;
@ExcelProperty(value = "入职时间")
private Date hireDate;
}

controller

 // 设置响应头
resp.setContentType("application/vnd.ms-excel");
resp.setCharacterEncoding("utf-8");
// 设置防止中文名乱码
String filename = URLEncoder.encode("员工信息", "utf-8");
// 文件下载方式(附件下载还是在当前浏览器打开)
resp.setHeader("Content-disposition", "attachment;filename=" +
filename + ".xlsx");
// 构建写入到excel文件的数据
List<UserExcel> userExcels = new ArrayList<>();
UserExcel userExce1 = new UserExcel(1001, "张三", "男", 1333.33,
new Date());
UserExcel userExce2 = new UserExcel(1002, "李四", "男", 1356.83,
new Date());
UserExcel userExce3 = new UserExcel(1003, "王五", "男", 1883.66,
new Date());
UserExcel userExce4 = new UserExcel(1004, "赵六", "男", 1393.39,
new Date());
userExcels.add(userExce1);
userExcels.add(userExce2);
userExcels.add(userExce3);
userExcels.add(userExce4);
// 写入数据到excel
EasyExcel.write(resp.getOutputStream(), SysOperLog.class)
.sheet("用户信息")
.doWrite(logQuery);

axios文件下载!!!!的更多相关文章

  1. axios 文件下载代码 片段

    <script type="text/javascript"> axios({ method:'post', url: 'url', // 最好qs.stringify ...

  2. Spring boot + Vue axios 文件下载

    后端代码: @GetMapping("/{sn}") @ApiOperation(value = "获取文件",notes = "获取文件" ...

  3. vuede axios文件下载

    this.loading = true; this.$http({ baseURL: CLOUD_BASE_SERVER_URL,           url: '/audit/auditRun/ex ...

  4. vue+axios实现文件下载

    功能:点击导出按钮,提交请求,下载excel文件: 第一步:跟后端童鞋确认交付的接口的response header设置了 axios({ method: 'post', url: 'api/user ...

  5. vue+axios+springboot文件下载

    //前台代码 <el-button size="medium" type="primary" @click="downloadFile" ...

  6. 【问题解决】Axios调用文件下载获取不到文件名

    问题描述 自己开发了一个后端下载文件的接口,然后通过浏览器直接访问这个接口,浏览器能正确得到文件名并下载: 而使用Axios时发现获取不到,经过打印响应体发现响应头里没有文件名 而Java后端代码里是 ...

  7. 使用Typescript重构axios(二十五)——文件上传下载进度监控

    0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...

  8. 基于Vue + axios + WebApi + NPOI导出Excel文件

    一.前言 项目中前端采用的Element UI 框架, 远程数据请求,使用的是axios,后端接口框架采用的asp.net webapi,数据导出成Excel采用NPOI组件.其业务场景,主要是列表页 ...

  9. vue+iview 通过a标签实现文件下载

    vue+iview 通过a标签实现文件下载 方法一: 注意: 如果下载的文件放在本地目录下,一定要将模板文件放到 public 目录下,否则由于权限问题找不到文件 路径: 项目更目录-->pub ...

  10. vue+axios+elementUI文件上传与下载

    vue+axios+elementUI文件上传与下载 Simple_Learn 关注  0.5 2018.05.30 10:20 字数 209 阅读 15111评论 4喜欢 6 1.文件上传 这里主要 ...

随机推荐

  1. POE供电及PD的功率分级

    POE供电标准有IEEE802.3af和IEEE802.3at 802.3af,PSE最高提供15.5W的功率而PD端则为12.95W: 802.3at,PSE最高提供30W的功率而PD端则为25W: ...

  2. selenium+鼠标操作+键盘操作+下拉框+弹出框+滚动条+三种等待--代码

    鼠标操作 键盘操作 下拉框 弹出框 滚动条 1 from time import sleep 2 from selenium import webdriver 3 4 driver = webdriv ...

  3. ubuntu系统使用 sudo: cd:找不到命令

    1. https://blog.csdn.net/sazass/article/details/125694492 https://blog.csdn.net/weixin_34033624/arti ...

  4. 例题1:shell脚本

    题目总结: 1.搜索子域名的shell脚本 2.嗅探并抓去网页快照shell脚本 3.漏洞利用程序下载脚本 题目一:依次输入以下代码即可: 1.wget www.megacorpone.com  2. ...

  5. Python基础教程:字典

    字典 = {'键1':'值1','键2':'值2','键3':'值3',...} animal_dict = {'Cow':'Milk','Chicken':'egg'} 字典由键值对构成,这种键值对 ...

  6. SpringBoot3.0 + SpringSecurity6.0+JWT

    JWT_SpringSecurity SpringBoot3.0 + SpringSecurity6.0+JWT Spring Security 是 Spring 家族中的一个安全管理框架. 一般We ...

  7. IO流详解及常用方法

    1.1. 什么是IO流 IO流: Input/Output Stream 流: 指的是一串流动的数据, 在数据在流中按照指定的方向进行流动. 实现数据的读取.写入的功能. 1.2. IO流的使用场景 ...

  8. SpringBoot——入门及原理

    SpringBoot 用来简化 Spring应用开发,约定大于配置,去繁从简,是由 Pivotal团队提供的全新框架.其设计目的是用来简化新 Spring应用的初始搭建以及开发过程.该框架使用了特定的 ...

  9. golang pprof 监控系列(1) —— go trace 统计原理与使用

    golang pprof 监控系列(1) -- go trace 统计原理与使用 服务监控系列文章 服务监控系列视频 关于go tool trace的使用,网上有相当多的资料,但拿我之前初学golan ...

  10. 算法学习笔记(20): AC自动机

    AC自动机 前置知识: 字典树:可以参考我的另一篇文章 算法学习笔记(15): Trie(字典树) KMP:可以参考 KMP - Ricky2007,但是不理解KMP算法并不会对这个算法的理解产生影响 ...