Skip to content

usePointerLock

反应式 指针锁

¥Reactive pointer lock.

示例

基本用法

¥Basic Usage

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

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

组件用法

¥Component Usage

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

类型声明

typescript
type MaybeHTMLElement = HTMLElement | undefined | null
export interface UsePointerLockOptions extends ConfigurableDocument {}
/**
 * Reactive pointer lock.
 *
 * @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>

源代码

源代码示例文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号