vue下載后台傳過來的亂碼流的解決辦法


后台返回的亂碼流

解決辦法:

請求方式用的是axios,主要加關鍵的 {responseType: 'blob'}

axios封裝

export function postDownload(url, data) {
  return new Promise((resolve, reject) => {
    instance.post(url,data,{responseType: 'blob'}).then(response => {
      resolve(response);
    }, err => {
      reject(err)
    })
  })
}

下載插件 npm install js-file-download -S

運用:

下載excel時,后台設置了excel標題,要去請求頭去取,傳輸過程中文會有亂碼的情況,需要編碼下。

let fileDownload = require("js-file-download");

fileDownload(res.data,decodeURIComponent(res.headers['content-disposition'].split("=")[1]));

 


免責聲明!

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



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