useCountdown
Reactive countdown timer in seconds.
Package: @vueuse/core
Category: Time
Usage
import { useCountdown } from '@vueuse/core'
const countdownSeconds = 5
const { remaining, start, stop, pause, resume } = useCountdown(countdownSeconds, {
onComplete() {
},
onTick() {
}
})Options
| Option | Type | Default | Description |
|---|---|---|---|
| interval | MaybeRefOrGetter<number> |
- | Interval for the countdown in milliseconds. Default is 1000ms. |
| onComplete | () => void |
- | Callback function called when the countdown reaches 0. |
| onTick | () => void |
- | Callback function called on each tick of the countdown. |
| immediate | boolean |
false | Start the countdown immediately |
Returns
| Name | Type |
|---|---|
| remaining | shallowRef |
| reset | Ref |
| stop | Ref |
| start | Ref |
| pause | Ref |
| resume | Ref |
| isActive | Ref |