解决vue2 表格自适应

文章展示了如何在Vue.js应用中使用el-table组件,并通过`:max-height`属性结合`$refs`在mounted生命周期钩子内动态获取表格的高度,从而实现表格内容自适应的弹性布局。同时,代码还包括了分页功能和样式设置。
摘要由CSDN通过智能技术生成

 实现效果

 

body代码

给el-table一个属性: :max-height='maxHeight'

<temalate>
<div  class="auto_content">
// 表格
 <div class="table" ref="tableRef">
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        :max-height="maxHeight"
        border
        append-to-body
        @selection-change="selectCheckbox"
        @select-all="selectAllBox"
        v-loading="loading"
        highlight-current-row
      >
表格内容
 </el-table>
    </div>
// 分页区域
   <div class="page-container">
      <el-pagination
        :current-page="pagination.page"
        :page-sizes="[10, 15, 20, 25]"
        :page-size="pagination.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
        @current-change="currentChange"
        @size-change="sizeChange"
      >
      </el-pagination>
    </div>
</div>


</temalate>

css代码   弹性盒布局,给table  flex:1

.auto_content {
  margin-left: 20px;

  .shuru_input {
    width: 540px !important;
    margin-right: 10px !important;
  }
}
.btn_wrap {
  margin: 20px;
}
.table {
  margin: 0px 20px;
  flex: 1;
}
.page-container {
  padding-top: 10px;
  border-top: 1px solid #ddd;
  width: 100%;
  height: 60px;
  background-color: #fff;
}

js代码   在生命周期mounted动态监听变化的高度

  mounted() {
    this.$nextTick(() => {
      this.maxHeight = this.$refs.tableRef.clientHeight;
    });
  },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值