主题
useWindowFocus
使用 window.onfocus
和 window.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>