blob解決下載后端接口返回文件流亂碼問題


前端在發送請求時攜帶(responseType:‘blob’)

var token = sessionStorage.httpToken
axios.defaults.headers.common.token = token
axios({
  methods: 'GET',
  url: 'http://baidu.com',
  responseType: 'blob'
}).then(res => {
  let blob = new Blob([res.data], {type: 'application/xls'})
  let url = window.URL.createObjectURL(blob)
  // 重命名文件名稱
  let a = document.createElement('a')
  a.setAttribute('href', url)
  a.setAttribute('download', '123.xls')
  a.click()
})

 


免責聲明!

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



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