vue监听浏览器高度,动态修改table高度

<template>
  <el-form ref="searchFormRef"></el-form>
  <el-table :max-height="maxHeight"></el-table>
</template>
<script>
import { defineComponent, onMounted, reactive, ref } from 'vue'

export default defineComponent({
    setup() {
        const state = reactive({
          maxHeight: '760px'
        })

        const refs = {
            searchFormRef: ref(null)
        }

        onMounted(() => {
            methods.getTableHeight()
            window.onresize = () => {
                methods.getTableHeight()
            }
        })

        const methods = {
            getTableHeight: () => {
                let pageHeight = document.body.offsetHeight
                let formHeight = refs.searchFormRef.value.$el.clientHeight
                state.maxHeight = pageHeight - 159 - formHeight + 'px'
            }
        }
} })
</script>

 

posted @ 2022-05-05 15:58  北山1992  阅读(524)  评论(0)    收藏  举报