useSSRWidth
用于设置全局视口宽度,该宽度将在渲染依赖于视口宽度的 SSR 组件时使用,例如 useMediaQuery
或 useBreakpoints
用法
js
import { provideSSRWidth } from '@vueuse/core'
const app = createApp(App)
provideSSRWidth(500, app)
或在根组件中
vue
<script setup>
import { provideSSRWidth } from '@vueuse/core'
provideSSRWidth(500)
</script>
要检索子组件中需要的提供的值
vue
<script setup>
import { useSSRWidth } from '@vueuse/core'
const width = useSSRWidth()
</script>
类型声明
typescript
export declare function useSSRWidth(): number | undefined
export declare function provideSSRWidth(
width: number | null,
app?: App<unknown>,
): void