前端处理导出(可自定义,目前是非自定义这种)

  const res = await exportManualList({
        fields: exportCodes,
        ids: this.allCheckList
      })
      const href = window.URL.createObjectURL(res)
      const link = document.createElement('a')
      link.href = href
      link.download = '切片清单' + moment().format('YYYY-MM-DD HH:mm:ss') + '.xlsx'
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
      window.URL.revokeObjectURL(href)
接口:
export const exportManualList = (data) => {
  return request({
    url: 'aaaaaaaaaaa',
    method: 'post',
    data,
    responseType: 'blob'
  })
}
这里一定要  responseType: 'blob',要处理后端给的文件流

以上内容直接复制粘贴就可以使用,有问题可以评论问哈。

第二种前端导出方式:导出table表格内容,首先给table表格设置id,id="outTable",

下面是导出方法

  import XLSX from 'xlsx'
const FileSaver = require('file-saver')



exportSelections() {
      if (this.selectedTableData.length === 0) {
        this.$message.error('请选择需要导出的数据')
        return
      }
      const time = new Date().getTime()
      const random = this.getRandomNum(100, 1000)
      const wb = XLSX.utils.table_to_book(document.querySelector('#outTable'), { raw: true })
      const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' })
      FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), `病例数据${time}-${random}.xlsx`)
    },

// 生成随机数
export function getRandomNum(Min, Max) {
  var Range = Max - Min
  var Rand = Math.random()
  return (Min + Math.round(Rand * Range))
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值