根据页面动态自适应宽高(window.removeEventListener("resize", 方法名);)

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
<template>
    <el-table :height="tableHeight" :data="tableData">
        <el-table-column header-align="center" label="序号" align="center" width="50px">
                    <template slot-scope="scope">
                        <span>{{scope.$index+(pageIndex - 1) * pageSize + 1}}</span>
                    </template>
                </el-table-column>
        ...其他代码
    </el-table>
</template>
<script>
  export default {
    data(){
        return {
            windowWidth: "",
            windowHeight: "",<br>        iptWidth: "",<br>       pageIndex: 1,<br>        pageSize: 10,
        }
    },
    mounted(){
        // 添加监听事件onResize start 缺一不可
        this.onResize()
        window.addEventListener('resize', this.onResize);
    },
    methods: {
        // 页面缩放时重置高度
            onResize() {
                let that = this;
                that.windowWidth = document.documentElement.clientWidth; //获取屏幕宽度
                that.windowHeight = document.documentElement.clientHeight; //获取屏幕高度
                // console.log('屏幕高1=', that.windowHeight);
                if (that.windowWidth >= 1366 && that.windowWidth <= 1680) that.iptWidth = 200
                    if (that.windowWidth >= 1680 && that.windowWidth <= 1920) that.iptWidth = 280
                this.$nextTick(() => {
                    that.tableHeight = that.windowHeight - 136
                })
            },
    }
  }
</script>   

  

posted @   ℡北瞳少年、  阅读(257)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
点击右上角即可分享
微信分享提示