跳到主要内容

useSSRWidth

分类
导出大小
309 B
上次更改
3 个月前

用于设置一个全局视口宽度,该宽度将用于渲染依赖于视口宽度的 SSR 组件,例如 useMediaQueryuseBreakpoints

用法

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

或在根组件中

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

如果您需要在子组件中获取提供的值

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

类型声明

ts
export declare function 
useSSRWidth
(): number | undefined
export declare function
provideSSRWidth
(
width
: number | null,
app
?:
App
<unknown>,
): void

来源

源代码文档

贡献者

SerKo
Anthony Fu
Adrien Foulon

更新日志

v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
v12.1.0
55965 - feat: 为 useMediaQuery 和 useBreakpoints 添加可选的 SSR 支持 (#4317)

根据 MIT 许可证发布。