//导出数据
onExportClick() {
this.exportLoading = true
let param = {
guid: '1236'
}
exportToExcel(param).then(res => { //接口
this.downloadFile(res, '表格.xlsx')
this.exportLoading = false
})
},
// 保存文件流数据为文件
downloadFile(data, fileName) {
if (!data) {
return
}
let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
// 模拟A标签点击事件
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
前端下载二进制流的表格
最新推荐文章于 2023-03-09 11:56:23 发布