Skip to content

useDevice

检测当前尺寸是否比平板尺寸或者指定尺寸更小。

返回值

名称类型说明
widthRef<number>当前浏览器宽度
heightRef<number>当前浏览器高度
isTabletOrSmallerReadonly<globalThis.Ref<boolean>>是否比指定尺寸更小

UseDeviceOptions

code
ts
interface UseDeviceOptions extends UseWindowSizeOptions {
  /**
   *
   * @description
   * 自定义 isTabletOrSmaller 的判断尺寸。
   *
   * @default 768
   */
  media?: number
}

基础使用

ts
import { useDevice } from '@/hooks'

const { isTableOrSmaller } = useDevice()

Released under the MIT License.