I. HTML code
<El-Col: xs = "2": Md = "2": Sm = "3"> <El-button type = "primary" style = "width: 100%; "@ click. stop = "handledownloadexecl"> export </El-button> </El-Col>
Ii. JS Code
// Download excelhandledownloadexecl () {downloaddisabilitylistexcelapi (this. searchform). Then (Info => {If (! Info) {return} Let url = Window. URL. createobjecturl (Info) Let link = document. createelement ('A') link. style. display = 'none' link. href = URL link. setattribute ('id', 'downloadlink') link. setattribute ('Download', 'Disability information table .xls ') document. body. appendchild (Link) link. click () // Delete the added a link let objlink = document. getelementbyid ('downloadlink') document. body. removechild (objlink) // release the memory window. URL. revokeojbecturl (URL )})}
3. Axios settings
export function downloadDisabilityListExcelApi (data) { return service({ url: `/excel/excelDownloads`, method: ‘GET‘, params: data, responseType: ‘blob‘ })}
The back-end generates an Excel file based on the query conditions and returns it to the front-end for vue download.