Skip to content

Commit

Permalink
Table: fix set height to string ivalid problem (ElemeFE#15806)
Browse files Browse the repository at this point in the history
  • Loading branch information
feverdestiny committed May 31, 2019
1 parent feb0034 commit f4afdab
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/table/src/table-layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Vue from 'vue';
import scrollbarWidth from 'element-ui/src/utils/scrollbar-width';
import { parseHeight } from './util';

class TableLayout {
constructor(options) {
Expand Down Expand Up @@ -42,7 +41,7 @@ class TableLayout {

updateScrollY() {
const height = this.height;
if (height === null) return;
if (typeof height !== 'string' && typeof height !== 'number') return;
const bodyWrapper = this.table.bodyWrapper;
if (this.table.$el && bodyWrapper) {
const body = bodyWrapper.querySelector('.el-table__body');
Expand All @@ -53,13 +52,19 @@ class TableLayout {
setHeight(value, prop = 'height') {
if (Vue.prototype.$isServer) return;
const el = this.table.$el;
value = parseHeight(value);
if (typeof value === 'string' && /^\d+$/.test(value)) {
value = Number(value);
}
this.height = value;

if (!el && (value || value === 0)) return Vue.nextTick(() => this.setHeight(value, prop));

if (value) {
el.style[prop] = `${value}px`;
if (typeof value === 'number') {
el.style[prop] = value + 'px';

this.updateElsHeight();
} else if (typeof value === 'string') {
el.style[prop] = value;
this.updateElsHeight();
}
}
Expand Down

0 comments on commit f4afdab

Please sign in to comment.