(办公)vue下载excel,后台用post方法
2024-08-28 22:49:17
后台方法的参数必须是@RequestBody修饰的。
前台关键代码:
axios ( {
method : 'post',
url : api.exportPlayTime , // 请求地址
data : {
choose : type,
begindate : startDate,
enddate : endDate
},
responseType : 'arraybuffer',
observe: 'response',
} )
.then ( ( res ) => { const fileName = ""+filename+".xlsx"
let blob = new Blob([res.data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
if ( 'download' in document.createElement ( 'a' ) ) { // 非IE下载
const elink = document.createElement ( 'a' )
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL ( blob )
document.body.appendChild ( elink )
elink.click ()
URL.revokeObjectURL ( elink.href ) // 释放URL 对象
document.body.removeChild ( elink )
} else { // IE10+下载
navigator.msSaveBlob ( blob, fileName )
} })
download(data) {
if (!data) {
return
}
let url = window.URL.createObjectURL(new Blob([data]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', 'excel.xlsx') document.body.appendChild(link)
link.click()
},
最新文章
- VS2013中web项目中自动生成的ASP.NET Identity代码思考
- Git管理项目实例说明-记录和跟踪项目
- [ACM_模拟] ZJUT 1155 爱乐大街的门牌号 (规律 长为n的含k个逆序数的最小字典序)
- URAL 1097 Square Country 2 离散化
- apache common包下的StringUtils的join方法
- 关于xml的一些知识,DTD,XSD
- eclipse.ini配置eclipse的启动参数
- CI(-)框架结构
- 搭建实时同步data guard的最高可用-切换主备
- 调试经验--硬盘U菜
- perl的Getopt::Long和pod::usage ?
- 怎样看paper 最有效率
- Amazon新一代云端关系数据库Aurora(上)
- 手把手在Ubuntu上面安装Docker
- shell脚本--初识CGI
- (贪心 优先队列)P1090合并果子 洛谷
- js 面向对象的三大特性
- Could not write file: C:\......\.classpath
- a标签点击后,保证后来的样式
- 普通用户su 到root,无需密码方式,及iptables封掉本机某个端口,core文件配置