//调取接口post方式获得文件流
store.exportCheck(params).then(res => {
exportExcel('人员批量导出数据',res)
})
//api中要修改文件头'{ responseType: 'blob', }',只能放在请求得第三个位置上
export const downLoad = (params) => Network.post('/接口地址', params, { responseType: 'blob', });
//excel导出方法,相当于模拟点击效果
const exportExcel = (exportName,res) => {
let filename = `${exportName}.xls`
let eleLink = document.createElement('a')
eleLink.download = filename
eleLink.style.display = 'none'
let blob = new Blob([res], {type: "application/vnd.ms-excel"})
const hrefUrl = URL.createObjectURL(blob);
eleLink.href = hrefUrl
// 触发点击
document.body.appendChild(eleLink)
eleLink.click()
// 然后移除
document.body.removeChild(eleLink)
};
【vue 3】blob文件流 导出 excel 表格
最新推荐文章于 2024-05-05 16:18:15 发布