vue cli3.0^版本处理文件下载的问题


1 downloadFile(url, fileName) { 2 axios.get(url, { responseType: 'blob' })

3 .then(({ data }) => { 4 // 为了简单起见这里blob的mime类型 固定写死了 5 let type = 'application/pdf;' //'image/png' 6 let blob = new Blob([data], { type: type }) 7 let link = document.createElement('a'); 8 link.href = window.URL.createObjectURL(blob); 9 link.download = fileName || url.split('/').pop(); 10 link.click(); 11 }).catch(error => { 12 alert(error) 13 }) 14 },

 

posted @ 2019-11-15 14:57  codehwj  阅读(288)  评论(0)    收藏  举报