From 63f2e0f4c4bb15b08ac91f1490adfa5cd14cdf41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Wed, 15 Mar 2017 15:50:28 +0800 Subject: [PATCH] fixed Table bug when remove a row of data when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data --- src/components/table/table.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/table/table.vue b/src/components/table/table.vue index 013946e9..0d1ba172 100644 --- a/src/components/table/table.vue +++ b/src/components/table/table.vue @@ -173,7 +173,8 @@ bodyHeight: 0, bodyRealHeight: 0, scrollBarWidth: getScrollBarSize(), - currentContent: this.content + currentContent: this.content, + cloneData: deepCopy(this.data) // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data }; }, computed: { @@ -357,16 +358,16 @@ } } this.objData[_index]._isHighlight = true; - const oldData = oldIndex < 0 ? null : JSON.parse(JSON.stringify(this.data[oldIndex])); - this.$emit('on-current-change', JSON.parse(JSON.stringify(this.data[_index])), oldData); + const oldData = oldIndex < 0 ? null : JSON.parse(JSON.stringify(this.cloneData[oldIndex])); + this.$emit('on-current-change', JSON.parse(JSON.stringify(this.cloneData[_index])), oldData); }, clickCurrentRow (_index) { this.highlightCurrentRow (_index); - this.$emit('on-row-click', JSON.parse(JSON.stringify(this.data[_index]))); + this.$emit('on-row-click', JSON.parse(JSON.stringify(this.cloneData[_index]))); }, dblclickCurrentRow (_index) { this.highlightCurrentRow (_index); - this.$emit('on-row-dblclick', JSON.parse(JSON.stringify(this.data[_index]))); + this.$emit('on-row-dblclick', JSON.parse(JSON.stringify(this.cloneData[_index]))); }, getSelection () { let selectionIndexes = []; @@ -663,6 +664,10 @@ this.objData = this.makeObjData(); this.rebuildData = this.makeDataWithSortAndFilter(); this.handleResize(); + // here will trigger before clickCurrentRow, so use async + setTimeout(() => { + this.cloneData = deepCopy(this.data); + }, 0); }, deep: true },