From 58e81ffad08349251aba693bb7d6a405ec7db421 Mon Sep 17 00:00:00 2001 From: chenghongxing <1126263215@qq.com> Date: Sat, 25 Jul 2020 13:19:12 +0800 Subject: [PATCH] chore: optimize the code of StandardTable.vue; :star2: --- src/components/table/StandardTable.vue | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/components/table/StandardTable.vue b/src/components/table/StandardTable.vue index 7fc809f..a66a4b7 100644 --- a/src/components/table/StandardTable.vue +++ b/src/components/table/StandardTable.vue @@ -61,26 +61,23 @@ export default { this.$emit('selectedRowChange', selectedRowKeys, selectedRows) }, initTotalList (columns) { - const totalList = [] - columns.forEach(column => { - if (column.needTotal) { - totalList.push({...column, total: 0}) - } - }) + const totalList = columns.filter(item => item.needTotal) + .map(item => { + return { + ...item, + total: 0 + } + }) return totalList }, getScopedSlots(columns) { let scopedSlots = columns.filter(item => item.scopedSlots).map(item => item.scopedSlots) - scopedSlots = scopedSlots.flatMap(item => { - return Object.keys(item).map(key => item[key]) - }) + scopedSlots = scopedSlots.flatMap(item => Object.values(item)) return scopedSlots }, getSlots(columns) { let slots = columns.filter(item => item.slots).map(item => item.slots) - slots = slots.flatMap(item => { - return Object.keys(item).map(key => item[key]) - }) + slots = slots.flatMap(item => Object.values(item)) return slots }, onClear() {