Skip to content

useWindowFocus

Category
Export Size
590 B
Last Changed
2 months ago

使用 window.onfocuswindow.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>

Source

SourceDemoDocs

Contributors

Anthony Fu
丶远方
IlyaL
vaaski
Fernando Fernández
Anthony Fu
vaakian X

Changelog

dd316 - feat: use passive event handlers everywhere is possible (#4477)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)

Released under the MIT License.