前置條件:後臺接口返回二進制流文件javascript
1、設置前端請求的的前端
responseType: 'blob'
2、接收請求數據並調用下載java
var content = res.data // 接口返回的二進制流
var filename = fileName.xls // 文件名,根據須要更改
var blob = new Blob([content], {type: 'application/vnd.ms-excel'}) // 轉化爲blob對象 if (window.navigator.msSaveOrOpenBlob) { // IE navigator.msSaveBlob(blob, filename) } else { var aTag = document.createElement('a') aTag.download = filename aTag.href = URL.createObjectURL(blob) aTag.click() URL.revokeObjectURL(blob) }