element ui 解决table自适应问题

elementui table组件,在开发中会出现无法自适应父元素的情况,解决方法:

    this.$nextTick(function () {
      if (this.watchChanges) {
        console.log("执行了");
        this.tableHeight =
          window.innerHeight - this.$refs.moviesTable.$el.offsetTop - 145;

        // 监听窗口大小变化
        let that = this;
        window.onresize = function () {
          //this.$refs.moviesTable.$el.offsetTop:表格距离浏览器的高度
          that.tableHeight =
            window.innerHeight - that.$refs.moviesTable.$el.offsetTop - 145;
        };
      }
    });
 
可以加if条件来控制自适应。
this.$nextTick,当dom更新时触发,加if判断是为了在表格切换dom时避免找不到dom,出现报错的情况。
 

 

 

 可以加if条件来控制自适应。

this.$nextTick,当dom更新时触发,加if判断是为了在表格切换dom时避免找不到dom,出现报错的情况。

elementui table组件,在开发中会出现无法自适应父元素的情况,以上是解决方法。

posted @ 2022-08-26 11:21  勇敢牛牛20  阅读(994)  评论(0)    收藏  举报