代码如下
// 下载 handleDownload() { this.downloadLoading = true import('@/vendor/Export2Excel').then(excel => { // excel表格的表头 const tHeader = ['timestamp', 'title', 'type', 'importance', 'status'] const filterVal = ['timestamp', 'title', 'type', 'importance', 'status'] const data = this.formatJson(filterVal) console.log(data); return excel.export_json_to_excel({ header: tHeader, data, filename: 'table-list' }) this.downloadLoading = false }) },
1.文件引入:@/vendor/Export2Excel
2.tHeader为excel表格的表头字段
3.相应字段通过如下的方法在所有数据list中获得(运用两个map方法)
formatJson(filterVal) { return this.list.map(v => filterVal.map(j => { if (j === 'timestamp') { return parseTime(v[j]) } else { return v[j] } }) ) },