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); // 释放内存
    }

 

posted @ 2020-10-22 10:50  ExpectoPatronum—S  阅读(2589)  评论(0编辑  收藏  举报