动态给div赋值高,使页面高度100%

发布时间 2023-12-22 11:51:53作者: 鼓舞飞扬
import { ref, onMounted, onUnmounted, computed, nextTick } from 'vue'

const boxRef = ref()
const searchBoxRef = ref()
const tableBoxHeight = ref(0)

const computedTableBoxHeight = () => {
  const searchBoxHeight = searchBoxRef.value.clientHeight // 获取DIV的高度
  const boxHeight = boxRef.value.clientHeight
  tableBoxHeight.value = boxHeight - searchBoxHeight - 10
}
const packUp = async () => {
  showSearchItem.value = !showSearchItem.value
  await nextTick()
  computedTableBoxHeight()
}
onMounted(() => {
  computedTableBoxHeight()
  window.addEventListener('resize', resizeWindow)
})
onUnmounted(() => {
  window.removeEventListener('resize', resizeWindow)
})
const resizeWindow = () => {
  computedTableBoxHeight()
}