需求是這樣的......前端
具體實現,前端拿到後端返回回來的數據,而後經過Blob實現下載,文件內容樣式啥的都是後端寫的後端
script代碼:app
這裏的data就是後端返回回來的數據,此方法兼容IEthis
1 download(data) { 2 if (!data) { 3 return; 4 } 5 let blob = new Blob([data], { 6 type: 7 "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8" 8 }); 9 let url = window.URL.createObjectURL(blob); 10 let fileName = this.data.plan_no + "出團通知單.docx"; 11 if ("download" in document.createElement("a")) { 12 const a = document.createElement("a"); 13 a.href = url; 14 a.download = fileName; 15 a.style.display = "none"; 16 document.body.appendChild(a); 17 a.click(); 18 URL.revokeObjectURL(a.href); 19 document.body.removeChild(a); 20 } else { 21 navigator.msSaveBlob(blob, fileName); 22 } 23 }