blob形式导出Excel
程序员文章站
2022-03-15 13:37:18
...
export function getParticipantList(param) {
return ecloudRequest({
url: "",
method: "get",
params: param,
responseType: param.isExport ? 'blob' : ''
});
}
接口返回处理
const blob = new Blob([res])
const fileName = ''
if (navigator.userAgent.indexOf("Trident") !== -1) {
window.navigator.msSaveOrOpenBlob(blob, fileName)
} else {
const a = document.createElement("a")
a.href = URL.createObjectURL(blob)
a.download = fileName
a.innerHTML = "导出"
a.style.display = "none"
document.body.appendChild(a) // 防止firefox无法触发click
a.click()
setTimeout(() => {
document.body.removeChild(a)
}, 10000)
}