作为学习笔记,我这里将getExcel方法封装起来然后全局调用的,不封装的写在后面
![](https://img.haomeiwen.com/i13916599/56cc539f6d63ce89.png)
引入getExcel方法 这样就OK啦
![](https://img.haomeiwen.com/i13916599/560a5b8bc6979d77.png)
不封装的
axios({
method: 'GET',
url: '/api',
params: params,
responseType: 'blob'
})then(res => {
const link = document.createElement('a')
let blob = new Blob([res],{type: 'application/vnd.ms-excel'});
link.style.display = 'none'
link.href = URL.createObjectURL(blob);
let num = ''
for(let i=0;i < 10;i++){
num += Math.ceil(Math.random() * 10)
}
link.setAttribute('download', '公共代码_' + num + '.xlsx')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})
网友评论