网络编程 
首页 > 网络编程 > 浏览文章

vue + axios get下载文件功能

(编辑:jimmy 日期: 2024/10/26 浏览:3 次 )

本文实例为大家分享了vue + axios 下载文件的具体代码,供大家参考,具体内容如下

这里是axios的get方法。post方法请点击这里=》here

vue + axios get下载文件功能

注意点:

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)">下载当天报表</button>

script

methods:{
 downloadReport(item,index){
 let date = item.plans[this.daysIndex[index]]
 let url = '/Ecp.Export.exportXls.jdn"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()
 })
 },
 }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:vue+axios实现post文件下载
下一篇:layer.open组件获取弹出层页面变量、函数的实例
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap