注意:最好不要使用封装的请求方法,直接axios请求
exportExcel(urls) {
let b = {
method:'post',
headers: {
'Content-Type': 'application/json'
},
responseType: "blob",
url:'/api'+urls
}
axios(b).then(response =>{
console.log(response)
const fileName = '项目资源使用情况.xlsx'
if ('download' in document.createElement('a')) { // 非IE下载
const blob = new Blob([response.data], { type: 'application/ms-excel' })
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)
}
})
},