1. window.location.href = ‘请求路径‘get方式} 2. fetch(‘请求路径方式拼接上去‘get方式).then(res => res.blob().then(blob => { const a = document.createElement(‘a‘) const url = window.URL.createObjectURL(blob) const filename = ‘aa.xlsx‘ a.href = url a.download = filename a.click() window.URL.revokeObjectURL(url) })) 3.this.exportData.campusId = this.campusIdthis.exportData.time = this.changeTimes(this.createEndTime)axios({ url:‘路径‘ method: ‘方式‘, type: ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet‘, data: 参数, responseType: ‘blob‘, timeout: 120000}).then(response => { const blob = new Blob([response.data]) const fileName =‘aa.xlsx‘ if (‘download‘ in document.createElement(‘a‘)) { // 非IE下载 const elink = document.createElement(‘a‘) elink.download = 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) } else { // IE10+下载 navigator.msSaveBlob(blob, fileName) }
原文地址:https://www.cnblogs.com/bt2882/p/11577632.html
时间: 2024-10-07 17:25:29