axios({
url: api.downUser,
method: 'get', responseType: 'arraybuffer',[1]
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
})
download().then(res=>{
console.log(res)
const content = res
const blob = new Blob([content])
// const date = moment().format('YYYY-MM-DD')
const fileName = `用户信息模板.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)
}
})
参考
- ^这句话不是加在header里