var res=res;//接口响应的数据
var elink = document.createElement('a');
elink.download = "文件.xls";
elink.style.display = 'none';
var blob = new Blob([res],{type: 'application/vnd.ms-excel'});
elink.href = window.URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
当使用axios下载文件乱码,解决方式如下:
axios({
method:'get',
url:url,
responseType:'arraybuffer'//重点是配置这里
})
.then(function(response) {
//响应结果
});
})