Skip to content

useWindowFocus

使用 window.onfocuswindow.onblur 事件反应式性地跟踪窗口焦点。

¥Reactively track window focus with window.onfocus and window.onblur events.

示例

💡 Click somewhere outside of the document to unfocus.

用法

¥Usage

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

const focused = useWindowFocus()

组件用法

¥Component Usage

vue
<template>
  <UseWindowFocus v-slot="{ focused }">
    Document Focus: {{ focused }}
  </UseWindowFocus>
</template>

类型声明

typescript
/**
 * Reactively track window focus with `window.onfocus` and `window.onblur`.
 *
 * @see https://vueuse.org/useWindowFocus
 */
export declare function useWindowFocus(
  options?: ConfigurableWindow,
): Ref<boolean>

源代码

源代码示例文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号