记录一下导出处理二进制流文件的方法

主要是请求头和.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);
                });
        }

版权声明:本文为weixin_46731239原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。