vhook

useResize


追踪 window 的大小

API

const { width, height } = useResize(cb, delay)

Params

参数名描述类型默认值
cbresize 时执行的回调(width: number, height: number) => anynull
delay防抖延时时间(为0则不作防抖)number200

Result

参数名描述类型
width只读,window.innerWidthDeepReadonly<Ref<number>>
height只读,window.innerHeightDeepReadonly<Ref<number>>

Example

Code

<template>
  <p>width: {{width}}</p>
  <p>height: {{height}}</p>
</template>
<script>
  import { useResize } from 'vhook'
  export default {
    setup () {
      return useResize()
    }
  }
</script>