export function downloadFile(obj, name, suffix = "xlsx") {
const url = window.URL.createObjectURL(new Blob([obj], {type: "application/vnd.ms-excel"}))
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
const fileName = name + '-' + parseTime(new Date()) + '.' + suffix
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
按照以上方式導出出現文件損壞提示, 原因是請求時少了請求頭responseType: ‘blob’
加上請求頭即可
轉自:https://blog.csdn.net/qq_38392623/article/details/118020562
