element ui表格自适应屏幕高度

vue + element ui项目遇到一个界面要求:

mounted() {

    this.$nextTick(function() {

      this.tableHeight = window.innerHeight - this.$refs.tableRef.$el.getBoundingClientRect().top - 137

      // 监听窗口大小变化

      // this.$refs.tableRef.$el.getBoundingClientRect().top:表格距离浏览器的高度

      var that = this

      window.onresize = function() {

        that.tableHeight = window.innerHeight - that.$refs.tableRef.$el.getBoundingClientRect().top - 137

      }

    })

  },

注:

this.$refs['通过设置ref获取到的dom元素'].getBoundingClientRect();

获取元素距离顶部的距离:

this.$refs.journalUpward.getBoundingClientRect().top

获取元素组件高度:

this.$refs.top.$el.offsetHeight

设置元素样式:

this.$refs.mask.style.top = 100 + 'px'

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容