Skip to content

useSSRWidth

类别
导出体积
309 B
上次更改
2 months ago

用于设置一个全局视口宽度,该宽度将在渲染依赖于视口宽度的 SSR 组件时使用,例如 useMediaQueryuseBreakpoints

用法

ts
import { 
provideSSRWidth
} from '@vueuse/core'
const
app
=
createApp
(App)
provideSSRWidth
(500,
app
)

或在根组件中

vue
<script setup lang="ts">
import { 
provideSSRWidth
} from '@vueuse/core'
provideSSRWidth
(500)
</script>

如果您在子组件中需要它,可以检索提供的值。

vue
<script setup lang="ts">
import { 
useSSRWidth
} from '@vueuse/core'
const
width
=
useSSRWidth
()
</script>

类型声明

ts
export declare function 
useSSRWidth
(): number | undefined
export declare function
provideSSRWidth
(
width
: number | null,
app
?:
App
<unknown>,
): void

源码

源码文档

贡献者

一纸忘忧
SerKo
Anthony Fu
Adrien Foulon

更新日志

d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
55965 - feat: add optional support for SSR in useMediaQuery and useBreakpoints (#4317)