Skip to content

useSSRWidth

类别
导出大小
342 B
最近修改
2 days ago

用于设置全局视口宽度,当渲染依赖视口宽度的 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>