exportClick() { //导出 let par = {} downAxiosFile('/personnel/change/perUser/exportXls', par).then((res) => { let { data } = res; let fileName = decodeURIComponent(res.headers["content-disposition"].split("=")[1]) if (!data) { this.$message.warning('文件下载失败') return } if (typeof window.navigator.msSaveBlob !== 'undefined') { window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), '在职列表.xls') } else { let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' })) let link = document.createElement('a') link.style.display = 'none' link.href = url link.setAttribute('download', fileName) document.body.appendChild(link) link.click() document.body.removeChild(link) //下载完成移除元素 window.URL.revokeObjectURL(url) //释放掉blob对象 } }) },
备注:axios返回的数据要从响应拦截器中取值
标签:vue,--,res,Content,window,link,blob,let,data From: https://www.cnblogs.com/wangshengli520/p/16780049.html