處理邏輯:獲取返回文件流,通過 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); } }