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

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

组件用法

¥Component Usage

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