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); // 释放内存
}
Original: https://www.cnblogs.com/gjths/p/13856876.html
Author: ExpectoPatronum—S
Title: VUE下载文件,下载后台返回的response
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/608460/
转载文章受原作者版权保护。转载请注明原作者出处!