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

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

或者在根组件中

¥Or in the root component

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

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

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

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