From f25f12527e6ae61bcca3a4b6d87ee869c7de84c4 Mon Sep 17 00:00:00 2001 From: huanghong Date: Sat, 17 Mar 2018 02:29:30 +0800 Subject: [PATCH] Refactor --- src/components/table/mixin.js | 4 ++-- src/components/table/table-head.vue | 2 +- src/components/table/table.vue | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/table/mixin.js b/src/components/table/mixin.js index 13bbaf8e..64f8e9c6 100644 --- a/src/components/table/mixin.js +++ b/src/components/table/mixin.js @@ -27,7 +27,7 @@ export default { // when browser has scrollBar,set a width to resolve scroll position bug if (width && this.columns.length === index + 1 && top && this.$parent.bodyHeight !== 0) { let scrollBarWidth = this.$parent.scrollBarWidth; - if (!this.$parent.showScrollBar) scrollBarWidth = 0; + if (!this.$parent.showVerticalScrollBar) scrollBarWidth = 0; width += scrollBarWidth; } // when fixed type,reset first right fixed column's width @@ -35,7 +35,7 @@ export default { const firstFixedIndex = this.columns.findIndex((col) => col.fixed === 'right'); if (firstFixedIndex === index) { let scrollBarWidth = this.$parent.scrollBarWidth; - if (!this.$parent.showScrollBar) scrollBarWidth = 0; + if (!this.$parent.showVerticalScrollBar) scrollBarWidth = 0; width += scrollBarWidth; } } diff --git a/src/components/table/table-head.vue b/src/components/table/table-head.vue index a2facca7..7962462a 100644 --- a/src/components/table/table-head.vue +++ b/src/components/table/table-head.vue @@ -86,7 +86,7 @@ styles () { const style = Object.assign({}, this.styleObject); let scrollBarWidth = this.$parent.scrollBarWidth; - if(!this.$parent.showScrollBar) scrollBarWidth = 0; + if(!this.$parent.showVerticalScrollBar) scrollBarWidth = 0; const width = this.$parent.bodyHeight === 0 ? parseInt(this.styleObject.width) : parseInt(this.styleObject.width) + scrollBarWidth; style.width = `${width}px`; return style; diff --git a/src/components/table/table.vue b/src/components/table/table.vue index 7841f702..5b13f018 100644 --- a/src/components/table/table.vue +++ b/src/components/table/table.vue @@ -187,7 +187,7 @@ scrollBarWidth: getScrollBarSize(), currentContext: this.context, cloneData: deepCopy(this.data), // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data - showScrollBar:false, + showVerticalScrollBar:false, }; }, computed: { @@ -378,20 +378,20 @@ this.fixedHeader(); if (this.$refs.tbody) { - let bodyContent = this.$refs.tbody.$el; - let className = bodyContent.parentElement.className; - bodyContent.parentElement.className = ''; - let bodyContentHeight = bodyContent.offsetHeight; - let bodyContentWidth = bodyContent.offsetWidth; - bodyContent.parentElement.className = className; - let bodyWidth = this.$refs.tbody.$el.parentElement.offsetWidth; - let bodyHeight = this.$refs.tbody.$el.parentElement.offsetHeight; + let bodyContentEl = this.$refs.tbody.$el; + let bodyEl = bodyContentEl.parentElement; + let className = bodyEl.className; + bodyEl.className = ''; + let bodyContentHeight = bodyContentEl.offsetHeight; + let bodyContentWidth = bodyContentEl.offsetWidth; + bodyEl.className = className; + let bodyWidth = bodyEl.offsetWidth; + let bodyHeight = bodyEl.offsetHeight; let scrollBarWidth = 0; if (bodyWidth < bodyContentWidth) { scrollBarWidth = this.scrollBarWidth; } - let show = this.bodyHeight? bodyHeight - scrollBarWidth < bodyContentHeight : false; - this.showScrollBar = show; + this.showVerticalScrollBar = this.bodyHeight? bodyHeight - scrollBarWidth < bodyContentHeight : false; } } });