Skip to content

useWindowFocus

Category
Export Size
681 B
Last Changed
4 days ago

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

Demo

💡 Click somewhere outside of the document to unfocus.

Usage

vue
<script setup lang="ts">
import { 
useWindowFocus
} from '@vueuse/core'
const
focused
=
useWindowFocus
()
</script> <template> <
div
>{{
focused
}}</
div
>
</template>

Component Usage

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

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

Type Declarations

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

Source

SourceDemoDocs

Contributors

NoiseFan

Changelog

No recent changes

Released under the MIT License.