Vue function that tracks whether user is being inactive.
function useIdle(
ms?: number,
events?: string[],
runOnMount?: boolean
): {
isIdle: Ref<boolean>;
isTracking: Ref<boolean>;
start: () => void;
stop: () => void;
}
ms: number
milliseconds to wait before deciding whether the user is being idleevents: string[]
list of events to track the user forrunOnMount: boolean
whether to start tracking idle state on mount,true
by default
isIdle: Ref<boolean>
it istrue
when the user is idle,false
otherwiseisTracking: Ref<boolean>
whether this function events are running or notstart: Function
the function used for start tracking the user's idle statestop: Function
the function used for stop tracking the user's idle state
<template>
<div>
<p>isIdle: {{ isIdle }}</p>
<button @click="start" v-if="!isTracking">Start tracking</button>
<button @click="stop" v-else>Stop tracking</button>
</div>
</template>
<script lang="ts">
import Vue from 'vue'
import { useIdle } from 'vue-use-kit'
export default Vue.extend({
name: 'UseIdleDemo',
setup() {
const { isIdle, isTracking, start, stop } = useIdle(2500)
return { isIdle, isTracking, start, stop }
}
})
</script>