前端管理系统根据权限下载后台返回的Excel表格 前端使用vue框架,不过无所谓,只是触发一个方法 前端使用vue框架,不过无所谓,只是触发一个方法 // 导出表格内容 const table1_ajax = function (url) { var xhr = new XMLHttpRequest(); var formData = new FormData(); xhr.open('get', '/api/SyCooperation/' + url); xhr.setRequestHeader("Authorization", sessionStorage.getItem("userId"));//设置请求参数,就是控制权限的时候后端向你传的验证 xhr.responseType = 'blob'; xhr.onload = function (e) { let blob = new Blob([xhr.response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' }); let downloadElement = document.createElement('a'); let href = window.URL.createObjectURL(blob); //创建下载的链接 downloadElement.href = href; downloadElement.download = 'demo.xls'; //下载后文件名 document.body.appendChild(downloadElement); downloadElement.click(); //点击下载 document.body.removeChild(downloadElement); //下载完成移除元素 window.URL.revokeObjectURL(href); //释放掉blob对象 }; xhr.send(formData); } export default table1_ajax