vue導出excel文件損壞


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM