前端下载二进制流文件

345 阅读1分钟

首先进行axios配置responseType: 'blob'

request({
    url: `${baseNew.manager}/platformPoiProductManager/report?${formatParam(params)}`,
    method: 'get',
    responseType: 'blob'
})

创建Blob对象,之后插入a标签,设置download名字

const url = window.URL.createObjectURL(new Blob([res]))
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', 'excel1111.xlsx')
document.body.appendChild(link)
link.click()