FileReader

FileReader MDN

Common methods of FileReader

readAsDataURL

FileReader.readAsDataURL()
Copy the code

Begins reading the specified content Blob, and when it’s done, the result property contains a data: URL representing the file data.

FileReader common event callback

FileReader.onload

reader.onload = e => { ... Event handler}Copy the code

Handler for the onload event. This event is emitted whenever the read operation completes successfully.

File stream handler function

/** * @description; * */ exportAndDownload(file, filename = 'data') { const reader = new FileReader() reader.readAsDataURL(file) reader.onload = e => { const a = Document.createelement ('a') a.townLoad = '${filename}.xlsx' a.href = e.target.result // The result property contains a data: the URL representing the file data. Document. The body. The appendChild (a) / / repair can't trigger the click in firefox a.c lick () document. Body. RemoveChild (a)}},Copy the code

ResponseType :”blob”;


 content-type: application/x-download
 
Copy the code

It is used to process stream files: