var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = "blob";
xhr.setRequestHeader('Authorization', 'Bearer ' + user_info.access_token)
xhr.onload = function () {
if (this.status === 200) {
var blob = this.response;
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = function (e) {
var a = document.createElement('a');
a.download = `filenname.xlsx`;
a.href = e.target.result;
a.click();
}
}
};
xhr.send()
export_applicants(params,{responseType: 'blob'}).then(res => {
const blob = new Blob([res.data], {
type: 'application/vnd.ms-excel;charset=utf-8'
})
const objectUrl = URL.createObjectURL(blob)
const a = document.createElement('a')
a.download = `filename.xlsx`
a.style.display = 'none'
a.href = objectUrl
document.body.appendChild(a)
a.click()
URL.revokeObjectURL(a.href)
document.body.removeChild(a)
})
带token的文件下载
于 2022-05-11 09:55:35 首次发布