963 markdown files reformatted with the repository's pinned prettier so pnpm format:check covers the folded tree like every other repo file. The formatter's embedded-language pass also normalized code fences (TS semicolons, closed HTML tags in examples, lowercased CSS hex colors, one renumbered list that skipped an index). Alphanumeric token deltas vs the fold commit were audited file-by-file; all are formatter-equivalent markup normalizations plus the four sanitized skills.
1.7 KiB
1.7 KiB
category
| category |
|---|
| Sensors |
useIdle
Tracks whether the user is being inactive.
Usage
import { useIdle } from '@vueuse/core';
const { idle, lastActive } = useIdle(5 * 60 * 1000); // 5 min
console.log(idle.value); // true or false
Programatically resetting:
import { useCounter, useIdle } from '@vueuse/core';
import { watch } from 'vue';
const { inc, count } = useCounter();
const { idle, lastActive, reset } = useIdle(5 * 60 * 1000); // 5 min
watch(idle, (idleValue) => {
if (idleValue) {
inc();
console.log(`Triggered ${count.value} times`);
reset(); // restarts the idle timer. Does not change lastActive value
}
});
Component Usage
<template>
<UseIdle v-slot="{ idle }" :timeout="5 * 60 * 1000"> Is Idle: {{ idle }} </UseIdle>
</template>
Type Declarations
export interface UseIdleOptions extends ConfigurableWindow, ConfigurableEventFilter {
/**
* Event names that listen to for detected user activity
*
* @default ['mousemove', 'mousedown', 'resize', 'keydown', 'touchstart', 'wheel']
*/
events?: WindowEventName[];
/**
* Listen for document visibility change
*
* @default true
*/
listenForVisibilityChange?: boolean;
/**
* Initial state of the ref idle
*
* @default false
*/
initialState?: boolean;
}
export interface UseIdleReturn extends Stoppable {
idle: ShallowRef<boolean>;
lastActive: ShallowRef<number>;
reset: () => void;
}
/**
* Tracks whether the user is being inactive.
*
* @see https://vueuse.org/useIdle
* @param timeout default to 1 minute
* @param options IdleOptions
*/
export declare function useIdle(timeout?: number, options?: UseIdleOptions): UseIdleReturn;