vue 根据后台返回文件流 导出数据

第一步

       <el-button @click="exportMessage">批量导出</el-button>

第二部

methods里面写方法

 exportMessage() {
           let data = {
                    search: this.ruleForm.searchPeople,      向后台传的参数
                    PageIndex: this.PageIndex,
                    pageSize: this.pageSize
                };
                let Authorization = localStorage.getItem("token");      token  
                axios.defaults.headers.common["Authorization"] = "Bearer " + Authorization;
                axios.post('http://114.55.169.186:1000/web/Export/exportTalent', data, {
                    responseType: 'blob'       这个 必须得加上
                }).then(res => {
                    // console.log(res,555)
                    console.log(res, '返回数据列');
                    const blob = new Blob([res.data], {
                        type: 'application/vnd.ms-excel'
                    });
                    console.log(blob, '----------0990');
                    const fileName = '招募人才.xlsx';       定义文件名字
                    const linkNode = document.createElement('a');    添加点击事件

                    linkNode.download = fileName; //a标签的download属性规定下载文件的名称
                    linkNode.style.display = 'none';
                    linkNode.href = URL.createObjectURL(blob); //生成一个Blob URL
                    document.body.appendChild(linkNode);
                    linkNode.click(); //模拟在按钮上的一次鼠标单击

                    URL.revokeObjectURL(linkNode.href); // 释放URL 对象
                    document.body.removeChild(linkNode);
                })

      },