导出表格功能

1.导出Excel 公共方法

import axios from 'axios'

//导出Excel公共方法

export function exportMethod(data){ axios({
    method:data.method,
    url:data.url,
    data:data.params,
    responseType:'blob'
  }).then(res=>{
    const link = document.createElement('a')
    let blob = new Blob([res.data],{type:'application/vnd.ms-excel'})
    link.style.display = 'none'
    link.href = URL.createObjectURL(blob)
    link.download = data.fileName
    document.bobdy.appendChild(link)
    link.click()
    document.body.removeChild(link)
  }).catch(error=>{
    this.$message.error({
      title:'错误',
      desc:'网络连接错误'
    })
  }) }

2.引用调取接口

import { exportMethod } from '@/utils/request' 

let myObj = {
  method:'post',
  url:API.downloadTacicsMange,
  fileName:'列表.xls',
  params:{
    name:this.name,
    age:this.age
  }
}
exportMethod(myObj);
 
posted @ 2022-03-28 09:05  小成-  阅读(46)  评论(0)    收藏  举报