let fileName = '****'; downExcel(fileName).then(res => { // 請求下載接口 // 處理返回的文件流 const content = res; const blob = new Blob([content]); const fileName = "Excel文件名稱" + ".xlsx"; if ("download" in document.createElement("a")) { // 非IE下載 const elink = document.createElement("a"); elink.download = fileName; elink.style.display = "none"; elink.href = URL.createObjectURL(blob); document.body.appendChild(elink); elink.click(); URL.revokeObjectURL(elink.href); // 釋放URL 對象 document.body.removeChild(elink); } else { // IE10+下載 navigator.msSaveBlob(blob, fileName); } });
// 走后台接口 獲取文件流
export function downExcel(fileName) { return request({ url:'**********?fileName=' + fileName, method:'get', headers: { "Content-Type": "application/json;application/octet-stream" }, responseType: "blob", params:'' }) }