Function: Click the Export button, submit the request, download Excel file;
Step one: Follow the back end child shoes to confirm the response header of the delivered interface is set
and returns the file stream.
Step Two: Modify the responsetype of the Axios request as a blob, taking the POST request as an example:
Axios ({ ' post ', ' api/user/', data: {' Fred ', ' Flintstone ' }, ' blob '= = {This. Download ( Response)}). Catch (Error) = {})
The third step: The request succeeds, after getting response, call the download function (create a tag, set the Download property, insert into the document and click)
methods: { // download file Download (data) { if (! Data) { return } = window. Url.createobjecturl (new Blob ([data])) = document.createelement (' A ') = ' None ' = url link.setattribute (' Download ', ' excel.xlsx ') Document.body.appendChild (link) link.click ()} }
Vue+axios Implementing File Download