之前有私信表示不能解析文件流,沉思一下,可能是没有在请求中设置
responseType:‘blob’
*/
把请求返回的数据,通过new再转一下
new Blob([res], {type: “application/vnd.ms-excel”})
type: “application/vnd.ms-excel” 需要下载什么类型的文件,类型改为相对的类型就可以
fileName 下载的文件名称
var blob = new Blob([res], {type: "application/vnd.ms-excel"}),
fileName = '下载.xls';
downFile(blob, fileName);
function downFile(blob, fileName) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, fileName);
} else {
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click();
window.URL.revokeObjectURL(link.href);
}
}