vue下载excel的实现代码后台用post方法
后台方法的参数必须是@RequestBody修饰的。
前台关键代码:
axios({
method:'post',
url:api.exportPlayTime,//请求地址
data:{
choose:type,
begindate:startDate,
enddate:endDate
},
responseType:'arraybuffer',
observe:'response',
})
.then((res)=>{
constfileName=""+filename+".xlsx"
letblob=newBlob([res.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
if('download'indocument.createElement('a')){//非IE下载
constelink=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
}
leturl=window.URL.createObjectURL(newBlob([data]))
letlink=document.createElement('a')
link.style.display='none'
link.href=url
link.setAttribute('download','excel.xlsx')
document.body.appendChild(link)
link.click()
},
总结
以上所述是小编给大家介绍的vue下载excel的实现代码后台用post方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
热门推荐
7 简短的二胎祝福语
10 简短霸气女儿生日 祝福语
11 祝福语高考小众诗句简短
12 元旦祝福语20秒简短
13 老师过年祝福语大全 简短
14 一生祝福语简短
15 产检祝福语简短霸气
16 朋友店开张祝福语简短
17 生日爱情祝福语大全简短
18 朋友女儿生日祝福语 简短