methods:{
//导出
handleDownloadInfo() {
this.$http.post('/excelService/ExportExcel/informationExportExcel',
this.pageRequest, //向后台传的值
{responseType:'arraybuffer'})
.then((res) => { // 处理返回的文件流
//方法一
const content = res.data;
const blob = new Blob([content])
const fileName = '我是filename.xls'
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
} else { // IE10+下载
navigator.msSaveBlob(blob)
}
//方法二
// let blob = new Blob([res.data],{type:"application/vnd.ms-excel;charset=UTF-8"});
// let objectURL = URL.createObjectURL(blob);
// window.location.href = objectURL;
})
},
}
导出功能实现
最新推荐文章于 2024-07-30 09:30:00 发布