vue + axios get下載文件功能
更新時間:2019年09月25日 10:35:12 作者:Shuah153
這篇文章主要為大家詳細介紹了vue + axios get下載文件功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue + axios 下載文件的具體代碼,供大家參考,具體內(nèi)容如下
這里是axios的get方法。post方法請點擊這里=》here

注意點:
Herder 請求頭需注意
- content-disposition:”attachment;filename=total.xls”
- content-type:”application/x-download;charset=utf-8”
axios請求的responseType為blob
- responseType:'blob',
template
<button class="os_myProduct_td6Div5Btn2" @click.stop="downloadReport(item,index)">下載當(dāng)天報表</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()
})
},
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
優(yōu)化Vue template中大量條件選擇v-if的方案分享
本文我們將給大家詳細的講解一下如何優(yōu)化Vue template 中的大量條件選擇v-if,文中通過代碼示例介紹的非常詳細,有詳細的優(yōu)化方案,感興趣的朋友可以參考閱讀下2023-07-07
VUE+node(express)實現(xiàn)前后端分離
在本篇文章里小編給大家分享的是關(guān)于VUE+node(express)前后端分離實例內(nèi)容,有需要的朋友們參考下。2019-10-10
Vue.js 2.0 移動端拍照壓縮圖片上傳預(yù)覽功能
這篇文章主要介紹了Vue.js 2.0 移動端拍照壓縮圖片上傳預(yù)覽功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-03-03

