vue导出excel实现思路

我了解的方法
第一种:安装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) 
            })

这两种方法有什么区别,哪个方法好

阅读 2.5k
2 个回答

第一种是前台导出
需要查看浏览器对xlsx的支持, 如果数据量大了不合适,会很卡

第二种是后台导出,需要后台写接口支持。 后端返回文件,前台再导出。 可以支持多数据量。

我觉得第二种好

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题