Dowload(url, fileName) { let xmlResquest = new XMLHttpRequest(); xmlResquest.open('GET', url, true); xmlResquest.setRequestHeader('Content-type', 'application/json'); xmlResquest.setRequestHeader( 'Authorization', this.$store.getters.getToken() ); xmlResquest.responseType = 'blob'; xmlResquest.onload = function (oEvent) { if (xmlResquest.status != 200) { this.$message({ type: 'error', message: '下载文件出错了..' }); return; } const downloadLink = document.createElement('a'); let content = xmlResquest.response; let blob = new Blob([content]); downloadLink.href = URL.createObjectURL(blob);; downloadLink.setAttribute('download', fileName); document.body.appendChild(downloadLink); downloadLink.click(); document.body.removeChild(downloadLink); }; xmlResquest.send(); }
标签:标签,downloadLink,JS,let,blob,document,xmlResquest,下载 From: https://www.cnblogs.com/tangchun/p/17738981.html