js download page 3 ways

1. window.location.href = 'request path' get manner 
}


2. FETCH ( 'request path spliced up' get embodiment) .then (RES => res.blob (). The then (BLOB => {
const A = document.createElement ( 'A')
const = window.URL.createObjectURL URL (BLOB)
const = filename 'aa.xlsx'
a.href = URL
a.download = filename
a.click ()
window.URL.revokeObjectURL (URL)
}))


3.this.exportData.campusId = this.campusId
this.exportData.time = this.changeTimes (this.createEndTime)
Axios ({
URL: 'path'
Method: 'mode',
type: 'file application / vnd.openxmlformats -officedocument.spreadsheetml.sheet ',
Data: parameters,
responseType:' BLOB ',
timeout:120000
}).then(response => {
const blob = new Blob([response.data])
const fileName ='aa.xlsx'
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)
}

Guess you like

Origin www.cnblogs.com/bt2882/p/11577632.html