axios({ method: 'post', // get 或者是post請求 url: '/api/street/jobRecord/export', // 請求地址 data: params, // 請求參數 headers: this.sessionKeys.sessionKey, responseType: 'blob' // 表明返回服務器返回的數據類型 }).then((res) => { // 處理返回的文件流 const content = res const blob = new Blob([content], { type:'application/vnd.ms- excel' }) const fileName = this.$t('analysis.detailedStatement') + '.xls' if ('download' in document.createElement('a')) { // 非IE下載 const elink = document.createElement('a') elink.download = fileName elink.style.display = 'none' elink.href = URL.createObjectURL(blob) elink.setAttribute('download', this.$t('analysis.detailedStatement') + '.xls') document.body.appendChild(elink) elink.click() URL.revokeObjectURL(elink.href) // 釋放URL 對象 document.body.removeChild(elink) } else { // IE10+下載 navigator.msSaveBlob(blob, fileName) } })

