Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useIdle.md
1---2category: Sensors3---45# useIdle67Tracks whether the user is being inactive.89## Usage1011```ts12import { useIdle } from '@vueuse/core'1314const { idle, lastActive } = useIdle(5 * 60 * 1000) // 5 min1516console.log(idle.value) // true or false17```1819Programatically resetting:2021```ts22import { useCounter, useIdle } from '@vueuse/core'23import { watch } from 'vue'2425const { inc, count } = useCounter()2627const { idle, lastActive, reset } = useIdle(5 * 60 * 1000) // 5 min2829watch(idle, (idleValue) => {30if (idleValue) {31inc()32console.log(`Triggered ${count.value} times`)33reset() // restarts the idle timer. Does not change lastActive value34}35})36```3738## Component Usage3940```vue41<template>42<UseIdle v-slot="{ idle }" :timeout="5 * 60 * 1000">43Is Idle: {{ idle }}44</UseIdle>45</template>46```4748## Type Declarations4950```ts51export interface UseIdleOptions52extends ConfigurableWindow, ConfigurableEventFilter {53/**54* Event names that listen to for detected user activity55*56* @default ['mousemove', 'mousedown', 'resize', 'keydown', 'touchstart', 'wheel']57*/58events?: WindowEventName[]59/**60* Listen for document visibility change61*62* @default true63*/64listenForVisibilityChange?: boolean65/**66* Initial state of the ref idle67*68* @default false69*/70initialState?: boolean71}72export interface UseIdleReturn extends Stoppable {73idle: ShallowRef<boolean>74lastActive: ShallowRef<number>75reset: () => void76}77/**78* Tracks whether the user is being inactive.79*80* @see https://vueuse.org/useIdle81* @param timeout default to 1 minute82* @param options IdleOptions83*/84export declare function useIdle(85timeout?: number,86options?: UseIdleOptions,87): UseIdleReturn88```89