From 792979b5b9140971babec51337a3e7671c913cfd Mon Sep 17 00:00:00 2001 From: hetech Date: Wed, 24 Apr 2019 19:48:49 +0800 Subject: [PATCH] Table: improve performance (#14868) --- packages/table/src/table-body.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/table/src/table-body.js b/packages/table/src/table-body.js index 5f51a9352..1a5720cea 100644 --- a/packages/table/src/table-body.js +++ b/packages/table/src/table-body.js @@ -1,5 +1,5 @@ import { getCell, getColumnByCell, getRowIdentity } from './util'; -import { getStyle, hasClass } from 'element-ui/src/utils/dom'; +import { getStyle, hasClass, removeClass, addClass } from 'element-ui/src/utils/dom'; import ElCheckbox from 'element-ui/packages/checkbox'; import ElTooltip from 'element-ui/packages/tooltip'; import debounce from 'throttle-debounce/debounce'; @@ -207,6 +207,23 @@ export default { } }, + watch: { + // don't trigger getter of currentRow in getCellClass. see https://jsfiddle.net/oe2b4hqt/ + // update DOM manually. see https://github.com/ElemeFE/element/pull/13954/files#diff-9b450c00d0a9dec0ffad5a3176972e40 + 'store.states.hoverRow'(newVal, oldVal) { + if (!this.store.states.isComplex) return; + const rows = this.$el.querySelectorAll('.el-table__row'); + const oldRow = rows[oldVal]; + const newRow = rows[newVal]; + if (oldRow) { + removeClass(oldRow, 'hover-row'); + } + if (newRow) { + addClass(newRow, 'hover-row'); + } + } + }, + data() { return { tooltipContent: '' @@ -281,10 +298,6 @@ export default { classes.push('current-row'); } - if (rowIndex === this.store.states.hoverRow) { - classes.push('hover-row'); - } - if (this.stripe && rowIndex % 2 === 1) { classes.push('el-table__row--striped'); }