js是获取不到文件流的名称(孤陋寡闻,如有办法麻烦留言告知),所以下载下来的文件需要给定文件名称,另外请求时需要加 responseType: "blob"
。
封装全局方法:
export function puclicDownload(data, title, type = "application/xlsl") {
let url = window.URL.createObjectURL(new Blob([data],{ type: type }) );
let a = document.createElement("a");
a.href = url;
a.setAttribute("download", title);
a.click();
window.URL.revokeObjectURL(url);
}