vue dialog弹出框随屏幕改变高度

动态改变高度是基于动态css样式进行设置,dialog中的高度是随内部元素高度变化,所以在dialog中的table添加class="tableClass",通过屏幕大小改变tableClass中的height,高度数值存储在sizeList中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<template>
    <div :style="sizeList">
        <div>
          <el-form :model="searchForm">
            <el-row>
                <el-col :span="2">
                    <el-button type="primary" @click="openDialog">打开弹出框</el-button>
                </el-col>
            </el-row>
          </el-form>
        </div>
        <el-dialog title="列表" :visible.sync="dialogVisible" width="1000px" top="5vh" :close-on-click-modal="false">
            <div>
                <el-table :data="list" border fit stripe class="tableClass" style="overflow:auto">
                    <el-table-column label="A" prop="A" min-width="120px"></el-table-column>
                    <el-table-column label="B" prop="B" min-width="120px"></el-table-column>
                    <el-table-column label="C" prop="C" min-width="120px"></el-table-column>
                </el-table>
             </div>
        </el-dialog>
    </div>
</template>
<script>
export default {
  data () {
    return {
      screenHeight:null,
      sizeList: {
        '--tableHeight': 410,
      },
      dialogVisible: false,
      list:[]
    }
  },
  watch:{
    screenHeight(val,oldVal){
      let num = val - 247;
      this.$set(this.sizeList,"--tableHeight",num+'px');
    }
  },
  methods: {
    openDialog(){
        this.dialogVisible = true;
    }
  },
  created() {
    this.screenHeight = document.body.clientHeight;
    let that = this;
    window.onresize = function(){
      that.$set(that,'screenHeight',document.body.clientHeight);
    }
  }
}
</script>
<style ref="styleSheet/scss" lang="scss" scoped>
    .tableClass{
        height: var(--tableHeight);
    }
</style>

  

posted @   陈橙橙橙子  阅读(367)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示