vue + axios get下載文件功能
本文實(shí)例為大家分享了vue + axios 下載文件的具體代碼,供大家參考,具體內(nèi)容如下
這里是axios的get方法。post方法請(qǐng)點(diǎn)擊這里=》here
注意點(diǎn):
Herder 請(qǐng)求頭需注意
- content-disposition:”attachment;filename=total.xls”
- content-type:”application/x-download;charset=utf-8”
axios請(qǐng)求的responseType為blob
- responseType:'blob',
template
<button class="os_myProduct_td6Div5Btn2" @click.stop="downloadReport(item,index)">下載當(dāng)天報(bào)表</button>
script
methods:{ downloadReport(item,index){ let date = item.plans[this.daysIndex[index]] let url = '/Ecp.Export.exportXls.jdn?entityId='+item.FId+'&date='+date.FDeparture_date+'&token=' + sessionStorage.getItem("token") this.axios({ method:'get', url:url, responseType:'blob', }) .then((data) => { if (!data) { return } debugger let url = window.URL.createObjectURL(data.data) let link = document.createElement('a') link.style.display = 'none' link.href = url link.setAttribute('download', 'excel.xls') document.body.appendChild(link) link.click() }) }, }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
優(yōu)化Vue template中大量條件選擇v-if的方案分享
本文我們將給大家詳細(xì)的講解一下如何優(yōu)化Vue template 中的大量條件選擇v-if,文中通過(guò)代碼示例介紹的非常詳細(xì),有詳細(xì)的優(yōu)化方案,感興趣的朋友可以參考閱讀下2023-07-07VUE+node(express)實(shí)現(xiàn)前后端分離
在本篇文章里小編給大家分享的是關(guān)于VUE+node(express)前后端分離實(shí)例內(nèi)容,有需要的朋友們參考下。2019-10-10Vue.js 2.0 移動(dòng)端拍照壓縮圖片上傳預(yù)覽功能
這篇文章主要介紹了Vue.js 2.0 移動(dòng)端拍照壓縮圖片上傳預(yù)覽功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03vue多次打包后出現(xiàn)瀏覽器緩存的問(wèn)題及解決
這篇文章主要介紹了vue多次打包后出現(xiàn)瀏覽器緩存的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08