後臺方法的參數必須是@RequestBody修飾的。 前臺關鍵代碼: ...
後臺方法的參數必須是@RequestBody修飾的。
前臺關鍵代碼:
axios ( { method : 'post', url : api.exportPlayTime , // 請求地址 data : { choose : type, begindate : startDate, enddate : endDate }, responseType : 'arraybuffer', observe: 'response', } ) .then ( ( res ) => { const fileName = ""+filename+".xlsx" let blob = new Blob([res.data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}); 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 ) } })
download(data) { if (!data) { return } let url = window.URL.createObjectURL(new Blob([data])) let link = document.createElement('a') link.style.display = 'none' link.href = url link.setAttribute('download', 'excel.xlsx') document.body.appendChild(link) link.click() },