/**导出 */ async toExcel() { // let result = await this.axios({ // method: 'get', // url: `issdc-manage/gameController/export.do`, // }); // window.open(`${this.serverUrl}/issdc-manage/gameController/export.do=${this.selectedRowKeys}`); await this.axios({ method: 'get', url: `entryFormController/export.do`, data: data, params: data, responseType: 'blob', //返回是个文件 }).then((response) => { download(response, data); //then直接下载,方法在下边 }); // 下载文件 function download(res) { let blob = new Blob([res.data], { type: res.headers['content-type'] }); //type是文件类,详情可以参阅blob文件类型 // 创建新的URL并指向File对象或者Blob对象的地址 let dis = res.headers['content-disposition']; let fileName = decodeURIComponent(dis.split('attachment;filename=')[1]); const blobURL = window.URL.createObjectURL(blob); // window.open(blobURL); var downloadElement = document.createElement('a'); downloadElement.href = blobURL; downloadElement.download = fileName; document.body.appendChild(downloadElement); downloadElement.click(); document.body.removeChild(downloadElement); window.URL.revokeObjectURL(blobURL); } },
标签:文件,vue,res,blobURL,导出,window,blob,downloadElement,data From: https://www.cnblogs.com/book-student/p/16714617.html