部分代碼如下
handleDownload() { if (this.multipleSelection.length) { this.downloadLoading = true import('@/vendor/Export2Excel').then(excel => { const tHeader = ['Id', 'Title', 'Author', 'Readings', 'Date'] const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time'] const list = this.multipleSelection const data = this.formatJson(filterVal, list) excel.export_json_to_excel({ header: tHeader, data, filename: this.filename }) this.$refs.multipleTable.clearSelection() this.downloadLoading = false }) } else { this.$message({ message: 'Please select at least one item', type: 'warning' }) } }, formatJson(filterVal, jsonData) { return jsonData.map(v => filterVal.map(j => v[j])) }
其中使用到了formatJson,改函數可以把對象轉為數據,把對象中的值轉為數組中的內容。
要轉的對象
轉化后的數組