监听浏览器窗口宽度

51 阅读1分钟

<template>
    {{ windowWidth }} 
    {{ windowHeight }} 
</template>

<script lang="ts" setup>
const windowWidth = ref(document.body.clientWidth)
const windowHeight = ref(document.body.clientHeight)

onMounted(()=>{
  window.onresize = () => {
      return (() => {
        windowWidth.value = document.documentElement.clientWidth 
        windowHeight.value = document.documentElement.clientHeight 
      })()
    }
})

</script>