vue + axios achieve downloaded in the background

downloadFile(){
downloadInstruction().then(res => {
var blob = new Blob([res.data]);
var downloadElement = document.createElement('a');
var href = window.URL.createObjectURL (blob); // create a download link
var fileName = 'Operation Manual .docx'
downloadElement.href = href;
downloadElement.download = fileName; // download file name after
document.body.appendChild(downloadElement);
downloadElement.click (); // Download
document.body.removeChild (downloadElement); // Download the complete removal of elements
window.URL.revokeObjectURL (href); // freed the blob
});
},
 
export function downloadInstruction (query) {
return request({
url: '/rts/main/downloadInstruction',
method: 'get',
params: query,
responseType:"blob"
})
}

Guess you like

Origin www.cnblogs.com/zhang-zhao/p/11275190.html