Skip to content

useScreenSafeArea

Category
Export Size
1.5 kB
Last Changed
15 minutes ago

响应式 env(safe-area-inset-*)

image

Demo

top:
right:
bottom:
left:

用法

为了使页面完全呈现在屏幕中,首先必须在 viewport meta 标签中设置额外属性 viewport-fit=cover,viewport meta 标签可能如下所示:

html
<meta name="viewport" content="initial-scale=1, viewport-fit=cover" />

然后我们可以在组件中使用 useScreenSafeArea 如下所示:

ts
import { useScreenSafeArea } from '@vueuse/core'

const {
  top,
  right,
  bottom,
  left,
} = useScreenSafeArea()

有关更多详细信息,请参阅此文档:Designing Websites for iPhone X

组件使用

vue
<template>
  <UseScreenSafeArea top right bottom left>
    content
  </UseScreenSafeArea>
</template>

类型声明

typescript
/**
 * 响应式 `env(safe-area-inset-*)`
 *
 * @see https://vueuse.org/useScreenSafeArea
 */
export declare function useScreenSafeArea(): {
  top: Ref<string, string>
  right: Ref<string, string>
  bottom: Ref<string, string>
  left: Ref<string, string>
  update: () => void
}

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
Anthony Fu
vaakian X
Ayaka Rizumu
Jelf

变更日志

v9.11.0 on 1/17/2023
d5321 - fix(components): mark defineComponent as pure (#2623)

Released under the MIT License.