/*
下載表格
*/
export const downloadFile = (url, fileName = '表格.xlsx') => {
axios({
url: url,
headers: {
// Authorization: getToken(),
},
responseType: 'blob',
}).then(res => {
const content = res
const blob = new Blob([content])
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)
}
})
}
js 表格下載
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.