28.下载 1.原生下载

1.原生下载

exportEpExcleData(){
const  _this=this
 this.init.exportLoading=true
const apiUrl=`${urlObj.exportEpExcleData}?regionCnName=${this.page.echartsParams.regionCnName}&repofficeCnName=${this.page.echartsParams.repofficeCnName}&endCustName=${this.page.echartsParams.endCustName}`
const xmlhttp=new XMLHttpRequest()
xmlhttp.open("GET",apiUrl,true)
xmlhttp.responseType="blob"
xmlhttp.onload=function(){if(this.status==200){const fileName=this.getResponseHeader("content-disposition").split(";")[1].split("=")[1].replace(/\"/g,"")
const blob=this.response
const url=window.URL.createObjectURL(blob)//创建下载链接
const el=document.createElement("a")//转换完成,创建一个a标签用于下载el.download=decodeURI(fileName)//下载的文件名el.href=url
document.body.appendChild(el)
el.click()
document.body.removeChild(el)//下载完成移除元素window.URL.revokeObjectURL(url)//释放掉blob对象
_this.init.exportLoading=false}}
xmlhttp.send()},

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章