1.axios的post方法中responseType的默认值是“json”,改为“blob”即可。
axios.post(url, data, {responseType: 'blob'})
.then(function (response) {
callback(response);
})
2.在成功的回调中可以这样写
callBack(res){
let blob = new Blob([res.data]);
let url = window.URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = url;
a.download = "xxx.xls"; // 这里的文件名可以去res的header中取
a.click();
// 释放url对象
window.URL.revokeObjectURL(url);
}