我了解的方法
第一种:安装xlsx file-saver依赖实现导出excel
第二种:
axios({
method: 'post',
url: 'http://localhost:19090/exportUser',
data: {
email: this.email,
userIdArray: this.userIdArray,
startRegisterDate: this.registerStartTime,
endRegisterDate: this.registerEndTime
},
responseType: 'blob'
}).then((res) => {
console.log(res)
const link = document.createElement('a')
let blob = new Blob([res.data],{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)
}).catch(error => {
this.$Notice.error({ title: '错误', desc: '网络连接错误' })
console.log(error)
})
这两种方法有什么区别,哪个方法好
楼主,你好~
最多的还是兼容性的问题。第二种写法不兼容IE10以下的,可以参考相关文章,前端实现Exce导出功能兼容性问题解析