iview/element的table高度动态设置

前言:

       在使用vue的框架的时候,其中列表是大家经常使用的功能,但是放到我们项目中的话,也有很多属性需要我们二次进行改动。

iview:

1、页面上:官方的话是推荐使用数字或者字符串,但我们需要的是动态,所以给他加一个动态值   :height="now_height"  

<Table
      ref="now_table"
      :height="now_height"
    >

</Table>
 data() {
    return {
      now_height: null //table高度
    };
  },

 window.innerHeight  当前页面的高度,

 this.$refs.now_table.$el.offsetTop  拿到的是当前指定table的 top值

我这里 -43 -100 是因为我上面还有导航栏还有别的元素,你可以根据你的实际情况

 mounted() {
    this.now_height = window.innerHeight - this.$refs.now_table.$el.offsetTop - 43 - 100
  },

element:  原理同上

<el-table
      ref="now_table"
      :height="now_height"
    >

</el-table>
 data() {
    return {
      now_height: null //table高度
    };
  },
 mounted() {
    this.now_height = window.innerHeight - this.$refs.now_table.$el.offsetTop - 43 - 100
  },

到此结束!


版权声明:本文为weixin_44727080原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。