// 下载文件的公共方法 export function downloadFile(file, fileName) { const blob = new Blob([file]) // IE及IE内核浏览器,ie10+ if (window.navigator.msSaveBlob) { try { window.navigator.msSaveBlob(blob, fileName) } catch (e) { console.log(e) } } else { // 其他浏览器 const downloadElement = document.createElement('a') const href = window.URL.createObjectURL(blob) // 创建下载的链接 downloadElement.href = href downloadElement.download = fileName + '.xlsx' // 下载后文件名 document.body.appendChild(downloadElement) downloadElement.click() // 点击下载 document.body.removeChild(downloadElement) // 下载完成移除元素 window.URL.revokeObjectURL(href) // 释放blob对象 } }