this.$axios({
method: 'post',
url: `/api`,
data: data,
responseType: 'blob'
}).then((res) => {
let 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 = res.headers['content-disposition'] //下载后文件名
let name = link.download.split('=')[1]
link.download = name //下载的文件名
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}).catch(error => {
this.$message.error('下载失败')
})
前端把后台返回的excel文件流转成excel文件并下载
最新推荐文章于 2024-02-27 14:05:18 发布