VUE下載文件,下載后台返回的response


Js文件中

import request from "../utils/request-flask-filedown"; //切圖下載
export function downloadMaps(params) { return request({ url: 'gh/cloud/dec/map/project/downloadMap', method: 'get', params }) }
request請求攔截處flask-filedown.js  
//在你axios 定義處 添加response返回類型
const service = axios.create({ responseType: 'blob', baseURL: "api", timeout: 15000 // request timeout
});

等你處理responese時候 

 const res = response.data; if (res!=null) { let blob = new Blob([res], { type: 'application/zip' }); let url = window.URL.createObjectURL(blob); const link = document.createElement('a'); // 創建a標簽
      link.href = url; link.download = '切圖'; // 重命名文件
 link.click(); URL.revokeObjectURL(url); // 釋放內存
    }

 


免責聲明!

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



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