excel下載文件正確?下載報(bào)錯(cuò)
// 下載二進(jìn)制文件
customDownLoadZipGet(data, fileName) {
const blob = new Blob([data], { type: 'application/vnd.ms-excel' }) //?把得到的結(jié)果用流對象轉(zhuǎn)一下
const a = document.createElement('a') // 創(chuàng)建一個(gè)<a></ a>標(biāo)簽
a.href = URL.createObjectURL(blob) //?將流文件寫入a標(biāo)簽的href屬性值
a.download = fileName // 設(shè)置文件名
a.style.display = 'none' //?藏起來a標(biāo)簽
document.body.appendChild(a) //?將a標(biāo)簽追加到文檔對象中
a.click() // 模擬點(diǎn)擊了a標(biāo)簽,會(huì)觸發(fā)a標(biāo)簽的href的讀取,瀏覽器就會(huì)自動(dòng)下載了
a.remove() //?一次性的用完就刪除a標(biāo)簽 },
//接口
Analysis(data)??????????.then((res)?=>?{????????????this.customDownLoadZipGet(res,?'test.xlsm')??????????}) //調(diào)用方法?xlsm是后端返回的excel格式?