跳到主要内容

usePointerLock

分类
导出大小
1.48 kB
上次更改
3 个月前

响应式的指针锁定

演示

基本用法

ts
import { 
usePointerLock
} from '@vueuse/core'
const {
isSupported
,
lock
,
unlock
,
element
,
triggerElement
} =
usePointerLock
()

组件用法

此函数还通过 @vueuse/components 包提供了一个无渲染组件版本。了解更多用法

vue
<template>
  <UsePointerLock v-slot="{ 
lock
}">
<
canvas
/>
<
button
@
click
="
lock
">
Lock Pointer on Canvas </
button
>
</UsePointerLock> </template>

类型声明

ts
export interface UsePointerLockOptions extends ConfigurableDocument {}
/**
 * Reactive pointer lock.
 *
 * @see https://vueuse.org.cn/usePointerLock
 * @param target
 * @param options
 *
 * @__NO_SIDE_EFFECTS__
 */
export declare function 
usePointerLock
(
target
?:
MaybeElementRef
,
options
?: UsePointerLockOptions,
): {
isSupported
:
ComputedRef
<boolean>
element
:
ShallowRef
<
MaybeElement
,
MaybeElement
>
triggerElement
:
ShallowRef
<
MaybeElement
,
MaybeElement
>
lock
: (
e
:
MaybeElementRef
| Event) =>
Promise
<HTMLElement | SVGElement>
unlock
: () =>
Promise
<boolean>
} export type
UsePointerLockReturn
=
ReturnType
<typeof
usePointerLock
>

来源

源代码演示文档

贡献者

Anthony Fu
IlyaL
SerKo
IlyaL
Robin
Fernando Fernández
Robin
Anthony Fu
Sergey Danilchenko

更新日志

8c521 - feat(components)!: 重构组件并使其保持一致 (#4912)
v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
v12.6.0
ce9e5 - fix(useMouse): 检查 MouseEvent 而不是 Touch 以兼容 FF (#4457)
v12.4.0
dd316 - feat: 尽可能在所有地方使用被动事件处理程序 (#4477)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v10.8.0
a086e - fix: 更严格的类型

根据 MIT 许可证发布。