1. // blobData 后台返回的文件流二进制数据
    2. // fileName 自定义文件名称
    3. // suffixName 文件后缀名
    4. // fileType 文件后缀名对应的type值
    5. function exportFile(blobData, fileName, suffixName, fileType) {
    6. let blob = new Blob([blobData], { type: fileType })
    7. let downloadElement = document.createElement('a')
    8. let href = window.URL.createObjectURL(blob) // 创建下载的链接
    9. downloadElement.href = href
    10. downloadElement.download = fileName+ suffixName // 下载后文件名
    11. document.body.appendChild(downloadElement)
    12. downloadElement.click() // 点击下载
    13. document.body.removeChild(downloadElement) // 下载完成移除元素
    14. }
    15. //示例:
    16. exportFile(blobData, '订单明细', '.xls', 'application/vnd.ms-excel');