Skip to content

usePointerLock

类别
导出体积
1.42 kB
上次更改
2 weeks ago

响应式的指针锁定

示例

基本用法

js
import { usePointerLock } from '@vueuse/core'

const { isSupported, lock, unlock, element, triggerElement } = usePointerLock()

组件用法

vue
<template>
  <UsePointerLock v-slot="{ lock }">
    <canvas />
    <button @click="lock">
      在画布上锁定指针
    </button>
  </UsePointerLock>
</template>

类型声明

typescript
type MaybeHTMLElement = HTMLElement | undefined | null
export interface UsePointerLockOptions extends ConfigurableDocument {}
/**
 * 响应式指针锁
 *
 * @see https://vueuse.org/usePointerLock
 * @param target
 * @param options
 */
export declare function usePointerLock(
  target?: MaybeElementRef<MaybeHTMLElement>,
  options?: UsePointerLockOptions,
): {
  isSupported: ComputedRef<boolean>
  element: Ref<MaybeHTMLElement, MaybeHTMLElement>
  triggerElement: Ref<MaybeHTMLElement, MaybeHTMLElement>
  lock: (e: MaybeElementRef<MaybeHTMLElement> | Event) => Promise<HTMLElement>
  unlock: () => Promise<boolean>
}
export type UsePointerLockReturn = ReturnType<typeof usePointerLock>

源码

源码演示文档

贡献者

一纸忘忧
Anthony Fu
Fernando Fernández
Robin
Anthony Fu
Sergey Danilchenko

更新日志

v12.4.0 on 1/10/2025
dd316 - feat: use passive event handlers everywhere is possible (#4477)
v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.8.0 on 2/20/2024
a086e - fix: stricter types
v9.11.0 on 1/17/2023
ae69f - feat: new function (#2590)