vue achieve word, pdf file export function

vue achieve word document or pdf export function, my project is: a return to the back-end document flow (figure below), then do the front-end document flow process to download the code as follows:

Axios from Import 'Axios' ; 
    axios.get (url` `, { // URL: interface address 
responseType:` arraybuffer` // must write 
}) 
.then (RES => {
 IF (== 200 is res.status ) { 
the let BLOB = new new Blob ([res.data], { 
type: `file application / msword` // Word document msword, pdf document into PDF
 }); 
the let the ObjectURL = URL.createObjectURL (BLOB); 
the let Link = document. createElement ( "a" ); 
the let fname = `` my documents; // name of the downloaded file 
link.href = the ObjectURL; 
link.setAttribute ( "download", fname);
document.body.appendChild(link);
link.click();
}else {
this.$message({
type: "error",
message: "导出失败"
})
}
});

 

Guess you like

Origin www.cnblogs.com/feifan1/p/11938307.html