使用插件 xlsx 导出表格,file-saver保存文件
vue-element-admin,源码中找的;导出上万条数据还是很快的
gitHub地址,/vendor/Export2Excel的js文件
使用方法
export_json_to_excel({header: res.header,data: res.exportData,filename: `${fileName}1-${exportData.length}`,autoWidth: true,bookType: "xlsx"})
对应数据处理
import('@/vendor/Export2Excel').then(excel => {const tHeader = ['Id', 'Title', 'Author', 'Readings', 'Date']const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time']const list = this.listconst data = this.formatJson(filterVal, list)excel.export_json_to_excel({header: tHeader,data,filename: this.filename,autoWidth: this.autoWidth,bookType: this.bookType})this.downloadLoading = false})formatJson(filterVal, jsonData) {return jsonData.map(v => filterVal.map(j => {if (j === 'timestamp') {return parseTime(v[j])} else {return v[j]}}))}
源码链接gitHub,数据处理