Skip to content

useWindowSize

类别
导出体积
1.49 kB
上次更改
2 months ago

响应式窗口大小

示例

Infinity x Infinity

用法

vue
<script setup lang="ts">
import { 
useWindowSize
} from '@vueuse/core'
const {
width
,
height
} =
useWindowSize
()
</script> <template> <
div
>
Width: {{
width
}}
Height: {{
height
}}
</
div
>
</template>

组件使用

vue
<template>
  <UseWindowSize v-slot="{ 
width
,
height
}">
Width: {{
width
}}
Height: {{
height
}}
</UseWindowSize> </template>

类型声明

ts
export interface UseWindowSizeOptions extends ConfigurableWindow {
  
initialWidth
?: number
initialHeight
?: number
/** * 监听窗口 `orientationchange` 事件 * * @default true */
listenOrientation
?: boolean
/** * 是否应将滚动条包含在宽度和高度中 * 仅在 `type` 为 `'inner'` 时有效 * * @default true */
includeScrollbar
?: boolean
/** * Use `window.innerWidth` or `window.outerWidth` or `window.visualViewport` * visualViewport documentation from MDN(https://developer.mozilla.org/zh-CN/docs/Web/API/VisualViewport) * @default 'inner' */
type
?: "inner" | "outer" | "visual"
} /** * 响应式窗口大小。 * * @see https://vueuse.org/useWindowSize * @param options * * @__NO_SIDE_EFFECTS__ */ export declare function
useWindowSize
(
options
?: UseWindowSizeOptions): {
width
:
ShallowRef
<number, number>
height
:
ShallowRef
<number, number>
} export type
UseWindowSizeReturn
=
ReturnType
<typeof
useWindowSize
>

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
Jelf
Antério Vieira
IlyaL
SerKo
青椒肉丝
IlyaL
Robin
Fernando Fernández
huiliangShen
Al-Khawarizmi
Indrek Ardel
Zhousg
vaakian X
vaakian X
Shinigami
wheat
Alex Kozack
Roman Pavlov

更新日志

8c521 - feat(components)!: refactor components and make them consistent (#4912)
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
dd316 - feat: use passive event handlers everywhere is possible (#4477)
e78ef - feat: add type: visual option that leverage visualViewport (#4395)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
bfba3 - feat: add ability to get outer sizes of the window (#3999)