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()},

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