跳到内容

usePointerLock

类别
导出大小
1.42 kB
最后更改
3 周前

响应式 指针锁定

演示

基本用法

js
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>

类型声明

typescript
export interface UsePointerLockOptions extends ConfigurableDocument {}
/**
 * Reactive pointer lock.
 *
 * @see https://vueuse.org.cn/usePointerLock
 * @param target
 * @param options
 */
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>

源码

SourceDemoDocs

贡献者

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

更新日志

v12.6.0 于 2/14/2025
ce9e5 - fix(useMouse): 检查 MouseEvent 而不是 Touch 以在 FF 中工作 (#4457)
v12.4.0 于 1/10/2025
dd316 - feat: 在所有可能的地方使用被动事件处理程序 (#4477)
v12.0.0-beta.1 于 11/21/2024
0a9ed - feat!: 删除 Vue 2 支持,优化捆绑包并清理 (#4349)
v10.8.0 于 2/20/2024
a086e - fix: 更严格的类型

根据 MIT 许可证发布。