diff --git a/src/components/table/table.vue b/src/components/table/table.vue index d0c5f97..9df5053 100644 --- a/src/components/table/table.vue +++ b/src/components/table/table.vue @@ -149,6 +149,10 @@ height: { type: [Number, String] }, + // 3.4.0 + maxHeight: { + type: [Number, String] + }, stripe: { type: Boolean, default: false @@ -275,6 +279,10 @@ const height = parseInt(this.height); style.height = `${height}px`; } + if (this.maxHeight) { + const maxHeight = parseInt(this.maxHeight); + style.maxHeight = `${maxHeight}px`; + } if (this.width) style.width = `${this.width}px`; return style; }, @@ -336,7 +344,11 @@ let style = {}; if (this.bodyHeight !== 0) { const height = this.bodyHeight; - style.height = `${height}px`; + if (this.height) { + style.height = `${height}px`; + } else if (this.maxHeight) { + style.maxHeight = `${height}px`; + } } return style; }, @@ -548,7 +560,7 @@ this.objData[_index]._isExpanded = status; this.$emit('on-expand', JSON.parse(JSON.stringify(this.cloneData[_index])), status); - if(this.height){ + if(this.height || this.maxHeight){ this.$nextTick(()=>this.fixedBody()); } }, @@ -578,12 +590,16 @@ }, fixedHeader () { - if (this.height) { + if (this.height || this.maxHeight) { this.$nextTick(() => { const titleHeight = parseInt(getStyle(this.$refs.title, 'height')) || 0; const headerHeight = parseInt(getStyle(this.$refs.header, 'height')) || 0; const footerHeight = parseInt(getStyle(this.$refs.footer, 'height')) || 0; - this.bodyHeight = this.height - titleHeight - headerHeight - footerHeight; + if (this.height) { + this.bodyHeight = this.height - titleHeight - headerHeight - footerHeight; + } else if (this.maxHeight) { + this.bodyHeight = this.maxHeight - titleHeight - headerHeight - footerHeight; + } this.$nextTick(()=>this.fixedBody()); }); } else { @@ -986,6 +1002,9 @@ height () { this.handleResize(); }, + maxHeight () { + this.handleResize(); + }, showHorizontalScrollBar () { this.handleResize(); }, diff --git a/src/styles/components/table.less b/src/styles/components/table.less index 994671a..b686080 100644 --- a/src/styles/components/table.less +++ b/src/styles/components/table.less @@ -7,6 +7,7 @@ border: 1px solid @border-color-base; border-bottom: 0; border-right: 0; + overflow: hidden; // 开启 max-height 时,没有 overflow: hidden,则底部多出 1px,早期没有 overflow 是因为有些控件没有加 transfer } width: inherit; height: 100%; -- libgit2 0.21.4