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 26 27 28 29 30 31 32 33 34 35 36
| import FileSaver from '../xxx/FileSaver.js';
const params = { }; return this.$http({ method: 'GET', url: '/download.json', responseType: 'arraybuffer', params: params }).then(function (response) { let body = response.data; let contentDisposition = response.headers('Content-Disposition'); let fileName; for (let key of contentDisposition.split(';')){ let name = key.split('=')[0].trim(); if (name === 'filename'){ fileName = key.split('=')[1].trim(); fileName = decodeURIComponent(escape(fileName)); fileName = fileName.replace(/"/g, ''); } } if (body) { let file = new Blob([body], { type: "application/octet-stream" }); FileSaver.saveAs(file, fileName); } else { } }).catch(error => { this.$log.log(error); });
|