1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| axios.get("http://localhost:3000/request/download", { params: { name: this.name }, responseType: "blob", }) .then((res) => { debugger; const content = res.data; const blob = new Blob([content]); const fileName = "12.txt"; if ("download" in document.createElement("a")) { const link = document.createElement("a"); const href = window.URL.createObjectURL(blob); link.href = href; link.download = fileName; document.body.appendChild(link); link.click(); document.body.removeChild(link); window.URL.revokeObjectURL(href); } else { navigator.msSaveBlob(blob, fileName); } });
|