处理逻辑:获取返回文件流,通过 Blob 对象构造文件后下载。
function download(data, filename, type="application/vnd.ms-excel") {
let file = new Blob([data], {
type: type
});
if (window.navigator.msSaveOrOpenBlob) {
// IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
} else {
// Others
let a = document.createElement("a");
let url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(() => {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
