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 }) } }
  • 相关阅读:
    POJ 1149
    最小费用最大流邻接表模板
    poj 1724 最短路+优先队列(两个约束条件)
    hdu 4786 最小生成树与最大生成树
    hdu 4081 最小生成树变形
    poj 3228 二分+最大流
    poj 2516 最小费用最大流
    hdu 3605 二分图多重匹配
    hdu 3605 最大流sap+二进制思想(啊啊)
    hdu 3572 最大流判断满流
  • 原文地址:https://www.cnblogs.com/lvlvlv/p/11714436.html
Copyright © 2011-2022 走看看