前端下载文件

export function downloadFile(data, fileName){
const a
= document.createElement('a') let href = window.URL.createObjectURL(new Blob(["\ufeff", data], { type: 'text/csv;charset=utf-8;' })) a.href = href a.download = decodeURIComponent(fileName) document.body.appendChild(a) a.click() document.body.removeChild(a) window.URL.revokeObjectURL(href) }

downloadSpuAnalysisReportNew()
.then(response => {
let data = response.data
let headers = response.headers
let fileName = filenameRegex(headers)
downloadFile(data, fileName)
}).catch(error => {
console.log(`donwload error: ${error}`)
})
 

 

posted @ 2022-04-07 11:09  阿磊小哥哥呀  阅读(34)  评论(0编辑  收藏  举报