Category | Sensors |
---|---|
Export Size | 977 B |
Last Changed | last month |
Tracks whether the user is being inactive.
import { useIdle } from '@vueuse/core' const { idle, lastActive } = useIdle(5 * 60 * 1000) // 5 min console.log(idle.value) // true or false
Programatically resetting:
import { watch } from 'vue' import { useCounter, useIdle } from '@vueuse/core' 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 } })
This function also provides a renderless component version via the
@vueuse/components
package. Learn more about the usage.
<UseIdle v-slot="{ idle }" :timeout="5 * 60 * 1000"> Is Idle: {{ idle }} </UseIdle>
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 { idle: Ref<boolean> lastActive: Ref<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
© 2019-present Anthony Fu
Licensed under the MIT License.
https://vueuse.org/core/useIdle/