useWindowFocus
使用 window.onfocus
和 window.onblur
事件来动态地跟踪窗口焦点状态。
Demo
💡 单击文档外的任何地方取消焦点。
用法
js
import { useWindowFocus } from '@vueuse/core'
const focused = useWindowFocus()
组件使用
vue
<template>
<UseWindowFocus v-slot="{ focused }">
Document Focus: {{ focused }}
</UseWindowFocus>
</template>
Type Declarations
typescript
/**
* Reactively track window focus with `window.onfocus` and `window.onblur`.
*
* @see https://vueuse.org/useWindowFocus
*/
export declare function useWindowFocus(
options?: ConfigurableWindow,
): ShallowRef<boolean>