VUE根据文件流下载EXC

//写入js方法
//axios
import request from '@/plugins/axios' function moveOutExc(url, params) { return request({ responseType: 'blob', url: url, method: 'get', params, }) }
//导出 export function moveOut(url, fileName, filters) { moveOutExc(url, filters).then(res
=> { const link = document.createElement('a') let blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8', }) link.style.display = 'none' link.href = URL.createObjectURL(blob) if (fileName) { link.download = fileName } else { link.download = '' } document.body.appendChild(link) link.click() //删除无用代码 }) }

全局挂载

import { moveOut } from './utils/loadFile'

Vue.prototype.moveOut = moveOut

调用

this.moveOut('/neighborhood/pointsList/export', '积分清单明细', {
        userId: this.id,
      })

第一个参数:后端url地址
第二个参数:导出文件名
第三个参数:过滤列表的查询条件

 

posted @ 2021-08-06 15:54  嘿,你好!  阅读(99)  评论(0编辑  收藏  举报