zoukankan      html  css  js  c++  java
  • vue 导出excel表格

    
    
    import { ACCESS_TOKEN } from '@/store/mutation-types'


    // 导出表格 // tableList:表格中的数据 // params:传入后端接口的参数 // api:后端接口的地址 // tableTitle:导出文件的名字 export const exportTable = (tableList, params, api, tableTitle) => { if (tableList.length > 0) { notification.success({ message: '成功', description: '正在导出列表,请稍等', duration: 1 }) axios({ method: 'post', url: api, headers: { 'Content-Type': 'application/json;charset=UTF-8', Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)//Vue.ls.get(ACCESS_TOKEN)获得token, }, responseType: 'arraybuffer',//改成这个值,导出的excel表格不会有数据损坏 data: params // data是添加到请求体(body)中的, 用于post请求。 }).then(res => { if (res.status === 200) { const link = document.createElement('a') const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) link.style.display = 'none' link.href = window.URL.createObjectURL(blob)//创建连接 link.download = tableTitle + '.xlsx'//将下载的excel表格命名 document.body.appendChild(link) link.click() document.body.removeChild(link) notification.success({ message: '成功', description: '导出成功', duration: 3 }) } }).catch(error => { notification.error({ message: '失败', description: '导出失败', duration: 3 }) }) } else { notification.error({ message: '失败', description: '表格中没有数据无法导出', duration: 3 }) } }
  • 相关阅读:
    day5 -常用模块
    day4装饰器-迭代器&&生成器
    h5 canvas 图片上传操作
    Tomcat上传文件报错:returned a response status of 403 Forbidden
    $.each遍历json对象
    Java求字符串中出现次数最多的字符
    线程池原理
    谈谈你对Hibernate的理解
    为什么要用 ORM? 和 JDBC 有何不一样?
    多线程有几种实现方法?同步有几种实现方法?(被问到)
  • 原文地址:https://www.cnblogs.com/lvlvlv/p/11714436.html
Copyright © 2011-2022 走看看