Skip to content

useFullscreen

类别
导出体积
1.23 kB
上次更改
6 minutes ago

响应式的全屏 API。它添加了方法,用于将特定元素 (及其后代) 呈现为全屏模式,并在不再需要时退出全屏模式。这使得可以使用用户的整个屏幕来呈现所需的内容,例如在线游戏,在全屏模式下移除所有浏览器用户界面元素和其他应用程序,直到关闭全屏模式为止。

示例

使用方法

ts
import { 
useFullscreen
} from '@vueuse/core'
const {
isFullscreen
,
enter
,
exit
,
toggle
} =
useFullscreen
()

指定元素全屏显示。某些平台 (例如 iOS 的 Safari) 仅允许在视频元素上全屏显示。

vue
<script setup lang="ts">
import { 
useFullscreen
} from '@vueuse/core'
import {
useTemplateRef
} from 'vue'
const
el
=
useTemplateRef
('el')
const {
isFullscreen
,
enter
,
exit
,
toggle
} =
useFullscreen
(
el
)
</script> <template> <
video
ref
="
el
" />
</template>

组件使用

html
<div>
  <UseFullscreen v-slot="{ toggle }">
    <video />
    <button @click="toggle">进入全屏模式</button>
  </UseFullscreen>
</div>

类型声明

ts
export interface UseFullscreenOptions extends ConfigurableDocument {
  /**
   * 卸载组件时自动退出全屏
   *
   * @default false
   */
  
autoExit
?: boolean
} /** * 响应式 Fullscreen API. * * @see https://vueuse.org/useFullscreen * @param target * @param options */ export declare function
useFullscreen
(
target
?:
MaybeElementRef
,
options
?: UseFullscreenOptions,
): {
isSupported
:
ComputedRef
<boolean>
isFullscreen
:
ShallowRef
<boolean, boolean>
enter
: () =>
Promise
<void>
exit
: () =>
Promise
<void>
toggle
: () =>
Promise
<void>
} export type
UseFullscreenReturn
=
ReturnType
<typeof
useFullscreen
>

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
Fernando Fernández
IlyaL
wheat
Antério Vieira
Arthur Darkstone
SerKo
Ben Lau
IlyaL
Anthony Fu
tawen
zaqvil
Yvan Zhu
vaakian X
Jelf
webfansplz
Shinigami
Alex Kozack

更新日志

8ac73 - fix: specify return types for request, exit, and enabl… (#4965)
8c521 - feat(components)!: refactor components and make them consistent (#4912)
09cbd - fix: get the correct initial state while mounted (#4745)
dd316 - feat: use passive event handlers everywhere is possible (#4477)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
14edb - fix: skip exiting when not in fullscreen mode (#3144)