前端

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. python 编程找出矩阵中的幸运数字:说明,在一个给定的M*N的矩阵(矩阵中的取值0-1024,且各不相同),如果某一个元素的值在同一行中最小,并且在同一列中元素最大,那么该数字为幸运数字。

    假设给定矩阵如下: matrix=[[10,36,52], [33,24,88], [66,76,99]] 那么输出结果应为66(同时满足条件) 代码如下: arr=[[10,36,52], [33, ...

  2. python调用java&反编译地址

    反编译工具地址: https://github.com/java-decompiler/jd-gui/releases 你想知道的JPype全在这里∞   先总结自己趟的坑 1. python进程是6 ...

  3. idea 切换database数据库方言

    在适配各种国产数据库时常常遇到存在数据库方言的情况,例如openGauss支持oracle兼容模式.. 在这种情况下,就需要在idea里对方言进行切换,否则无法执行oracle语法的sql. 1.连接 ...

  4. docker安装配置gitlab时的常用命令整理

    1.下载安装dockerapt install docker.io2.服务启动service docker start 3.拉取gitlabdocker pull beginor/gitlab-ce: ...

  5. leetcode-1072 Flip Columns For Maximum Number of Equal Rows

    Given a matrix consisting of 0s and 1s, we may choose any number of columns in the matrix and flip e ...

  6. linux查看mac地址

    1. ip addr show (ip address show .ip addr ) 查看本机ip和额外的一些信息 2.ifconfig -a  其中 HWaddr 就是mac地址 3.cat /s ...

  7. 今日Python相关练习

    1.计算日期范围内的所有日期 def get_date_list(begin_date,end_date): date_list = [] while begin_date <= end_dat ...

  8. Matlab笔记--Matlab概述(初登场)

    Matlab概述 安装MATLAB教程 可以参考这里:https://www.cnblogs.com/sixuwuxian/p/15858196.html Matlab的启动 右键图标,选择属性,可以 ...

  9. K8S部署应用详解

    # 前言 首先以SpringBoot应用为例介绍一下k8s的发布步骤. 1.从代码仓库下载代码,比如GitLab:2.接着是进行打包,比如使用Maven:3.编写Dockerfile文件,把步骤2产生 ...

  10. 使用K8S进行蓝绿部署的简明实操指南

    在之前的应用部署系列文章里,我们已经介绍过什么是蓝绿部署.如需回顾,点击下方文章链接即可重温.本文我们将会介绍如何使用 Kubernetes 实现蓝绿部署. 应用部署初探:3个主要阶段.4种常见模式 ...