当前位置: 首页 > news >正文

Vue 学习随笔系列二十二 —— 表格高度自适应

表格高度自适应

文章目录

  • 表格高度自适应
      • 1、方法一
      • 2、方法二


1、方法一

根据页面元素计算各自占比

<template>
  <div class="main">
    <div class="query-form" ref="Query">
      <QueryForm
        ref="QueryForm"
        @query="query"
      ></QueryForm>
    </div>

    <div class="table-box" ref="Temp">
      <TableModal
        ref="TableModal"
        :maxHeight="tempHeight-200"
        :tableData="tableData"
      ></TableModal>
      <!-- 分页 -->
      <div class="pagination-box flex-h flex-he">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="pageSizes"
          :current-page="pageNum"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          background
          small
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import QueryForm from './QueryForm.vue';
  import TableModal from './TableModal.vue';
  import FileSaver from "file-saver";

  export default {
    components: {
      QueryForm, 
      TableModal,
    },
    data() {
      return {
        tableData: [],
        total: 0,
        pageNum: 1,
        pageSize: 10,
        pageSizes: [10, 20, 50, 100],
        multipleSelection: [],
        maxHeight: 220,
        windowHeight: 0,  // 页面窗口高度
        tempHeight: 0,  // 元素高度
        QueryHeight: 0, // 查询框高度
      }
    },
    mounted() {
      this.query()

      // 自动获取元素高度
      var that = this;
      //刚进入页面时,获取窗口默认宽高度
      this.windowHeight = document.body.clientHeight
      this.QueryHeight = this.$refs.Query.offsetHeight
      //进入页面元素默认宽高
      // this.tempHeight = this.$refs.Temp.offsetHeight
      // this.maxHeight = this.tempHeight - 70
      this.tempHeight = this.windowHeight - this.QueryHeight

      window.onresize = () => {
        return (() => {
          //窗口缩放自动获取页面宽高
          window.fullHeight = document.documentElement.clientHeight;
          this.QueryHeight = this.$refs.Query.offsetHeight
          that.windowHeight = window.fullHeight; //高

          //窗口缩放自动获取元素宽高
          // this.tempHeight = this.$refs.Temp.offsetHeight //高
          // this.maxHeight = this.tempHeight - 70
          this.tempHeight = this.windowHeight - this.QueryHeight
        })()
      }
    },
    methods: {
      // 分页
      handleSizeChange (val) {
        this.pageSize = val
        this.query()
      },
      // 当前页
      handleCurrentChange (val) {
        this.pageNum = val
        this.query()
      },
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      query(){
        const form = this.$refs.QueryForm.getParams()
        const params = { ...form, pageNum: this.pageNum, pageSize: this.pageSize}
       	// ....
      },  
    },
  }
</script>

<style lang="scss" scoped>
.main  {
  padding: 10px;
  background-color: #F2F3F5;
} 

// 分页
.pagination-box {
  margin-top: 20px;
  float: right;
}
:deep .pagination-box .el-select--mini .el-input--mini .el-input__inner {
  height: 22px;
  line-height: 22px;
}

:deep .pagination-box .el-select--mini .el-input--mini .el-input__icon {
  line-height: 22px;
}
</style>

2、方法二

直接计算表格高度

<template>
    <div>
        <el-card>
            <QueryForm
                ref="queryForm"
                @query="query"
            ></QueryForm>
        </el-card>
    
        <TableColumn
            :tableData="tableData"
            :tableHeight="tableHeight"
        ></TableColumn>
    </div>

</template>

<script>
import QueryForm from "./queryForm.vue"
import TableColumn from './tableColumn.vue'

export default {
    components: {
        QueryForm,
        TableColumn,
    },
    data() {
        return {
            tableData: [],
            tableHeight: 0,
        }
    },
    created() {
      this.tableHeight = window.innerHeight - 340
    },
    mounted() {
        this.query()
        this.handleTableHeight()
    },
    methods: {
        handleTableHeight: function () {
            var _this = this;
            window.onresize = () => {
                _this.tableHeight = window.innerHeight - 346
            };
    
        },
        query() {
            const params = this.$refs.queryForm.getForm()
            // .......
        },

    }
}
</script>

<style lang="less" scoped >
    .el-card {
        margin: 0 0 10px 0;
    }
</style>
http://www.dtcms.com/a/109620.html

相关文章:

  • 一个完整的 HTTP/HTTPS 请求流程
  • 【电路笔记】-触发器的转换
  • ctfshow VIP题目限免 源码泄露
  • 【面试篇】Es
  • QTableWidget 中insertRow(0)(头插)和 insertRow(rowCount())(尾插)的性能差异
  • 服务器磁盘io性能监控和优化
  • c++中cin.ignore()的作用
  • Unirest:优雅的Java HTTP客户端库
  • CUDA概览
  • Python星球日记 - 第1天:欢迎来到Python星球
  • 十款Steam单机游戏
  • 2025-04-03 Latex学习1——本地配置Latex + VScode环境
  • PandasAI:当数据分析遇上自然语言处理
  • uni-app项目上传至gitee方法详细教程
  • Java代理(六)当前主流动态代理框架性能对比
  • 安全、可靠,企业内部im即时通讯软件选择
  • 十一、buildroot系统登录配置
  • 从0开始的构建的天气预报小时钟(基于STM32F407ZGT6,ESP8266 + SSD1309)——第1章 简单的介绍一下ESP8266和他的编程指令
  • Oracle数据库数据编程SQL<6.2 数据字典表之间的关联关系>
  • C++的智能指针weak_ptr和普通指针的区别
  • 第五课:高清修复和放大算法
  • MySQL安装教程(详细版)
  • Linux应用编程(文件IO)
  • 移远RG200U-CN模组WAKEUP_IN引脚
  • SAP ABAP AVL单元格颜色
  • 问题解决:glog中的LOG(INFO)与VLOG无法打印
  • 每日一题(小白)分析娱乐篇10
  • DDD与MVC扩展能力对比
  • Agent TARS与Manus的正面竞争
  • THUNLP_Multimodal_Excercise