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 }) } }
  • 相关阅读:
    [转]王垠的过去和现状
    支持向量机(SVM)基础
    C语言编程心得
    Fortran学习心得
    gdb使用心得
    大道至简第一章读后感
    第一个音符
    Exercise 1.20 最大公约数算法
    Exercise 1.19 Fast Fibonacci
    Exercise 1.16 1.17 1.18
  • 原文地址:https://www.cnblogs.com/lvlvlv/p/11714436.html
Copyright © 2011-2022 走看看