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