Skip to content

useSSRWidth

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

¥Used to set a global viewport width which will be used when rendering SSR components that rely on the viewport width like useMediaQuery or useBreakpoints

用法

¥Usage

js
import { provideSSRWidth } from '@vueuse/core'

const app = createApp(App)

provideSSRWidth(500, app)

或者在根组件中

¥Or in the root component

vue
<script setup>
import { provideSSRWidth } from '@vueuse/core'

provideSSRWidth(500)
</script>

如果在子组件中需要,则检索提供的值

¥To retrieve the provided value if you need it in a subcomponent

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

源代码

源代码文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号