Skip to content

useDocumentVisibility

Category
Export Size
692 B
Last Changed
last month

Reactively track document.visibilityState

Demo

💡 Minimize the page or switch tab then return

Usage

vue
<script setup lang="ts">
import { 
useDocumentVisibility
} from '@vueuse/core'
const
visibility
=
useDocumentVisibility
()
</script>

Component Usage

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

vue
<template>
  <UseDocumentVisibility v-slot="{ 
visibility
}">
Document Visibility: {{
visibility
}}
</UseDocumentVisibility> </template>

Type Declarations

ts
/**
 * Reactively track `document.visibilityState`.
 *
 * @see https://vueuse.org/useDocumentVisibility
 *
 * @__NO_SIDE_EFFECTS__
 */
export declare function 
useDocumentVisibility
(
options
?:
ConfigurableDocument
,
):
ShallowRef
<string, string>
export type
UseDocumentVisibilityReturn
=
ReturnType
<
typeof
useDocumentVisibility
>

Source

SourceDemoDocs

Contributors

Anthony Fu
Anthony Fu
Antério Vieira
IlyaL
SerKo
青椒肉丝
Robin
IlyaL
James Garbutt
Fernando Fernández
vaakian X
Jelf
Shinigami
wheat
Alex Kozack
Scott Bedard

Changelog

8c521 - feat(components)!: refactor components and make them consistent (#4912)
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
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.