export function createDownload(response, file, ext = 'xlsx') {
console.log(response, file, ext)
const blob = new Blob([response])
const fileName = `${file}.${ext}`
const link = document.createElement('a')
if ('download' in link) {
link.download = fileName
link.style.display = 'none'
link.href = URL.createObjectURL(blob)
document.body.appendChild(link)
link.click()
URL.revokeObjectURL(link.href)
document.body.removeChild(link)
} else {
navigator.msSaveBlob(blob, fileName)
}
}
传参:1.response为后端返回的乱码
2.file为你想要定义的文件名
调用方法:
ex: createDownload(res, '文件名')