1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
async downloadFile(url, params) { const request = { body: JSON.stringify(params), method: 'POST', headers: { 'Content-Type': 'application/json;charset=UTF-8', } } const response = await fetch(url, request); const filename = response.headers.get('Content-Disposition').split(';')[1].split('=')[1]; const blob = await response.blob() const link = document.createElement('a'); link.download = decodeURIComponent(filename); link.style.display = 'none' link.href = URL.createObjectURL(blob); document.body.appendChild(link); link.click(); URL.revokeObjectURL(link.href); document.body.removeChild(link); }
|