vue project implementation file download function

/ * * 
 * Downloaded file called 
 * @param the interface returns the data file name 
 * / 
Export function the downloadFile (RES, fileName) { 
  IF (! RES) {
     return 
  } 
  the let URL = window.URL.createObjectURL ( new new Blob ([RES]) ) 
  the let Link = document.createElement ( ' A ' ) 
  link.style.display = ' none ' 
  link.href = URL 
  link.setAttribute ( ' downloads ' , fileName) // filename 
  document.body.appendChild (Link) 
  Link. click ()
  document.body.removeChild (Link) // download is complete remove elements 
  window.URL.revokeObjectURL (URL) // relieve the blob 
}

 

 Incoming res file name and the page returned by the backend call call

Guess you like

Origin www.cnblogs.com/Hhuizi/p/11511932.html