主要是请求头和.then之后的内容
params和url写你自己的就行
exportCourseForDeptMgr() {
const params = {
currentPage: this.currentPage,
pageSize: this.pageSize,
where: {
courseCreate_eq: "1",
courseStatus_eq: "3",
applyDeptCode_eq: this.appUtils.getDeptCode(),
...this.studyResultForm
},
order: {
"course.createdDt": "desc"
}
};
let url =
this.apis.schoolLevelManagement.exportCourseForDeptMgr +
"?appId=" +
this.appUtils.getAppId();
axios
.post(url, params, {
responseType: "arraybuffer",
headers: {
Authorization: `Bearer ${localStorage.getItem(
"DP_TOKEN"
)}`
}
})
.then(res => {
const blob = new Blob([res.data]); // 处理文档流
// console.log(res, 'res');
const fileName = "已审核课程.xls";
const elink = document.createElement("a");
elink.download = decodeURI(fileName);
elink.style.display = "none";
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
})
.catch(function(error) {
console.log(error);
});
}