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/useCountdown.md
1---2category: Time3---45# useCountdown67Reactive countdown timer in seconds.89## Usage1011```ts12import { useCountdown } from '@vueuse/core'1314const countdownSeconds = 515const { remaining, start, stop, pause, resume } = useCountdown(countdownSeconds, {16onComplete() {1718},19onTick() {2021}22})23```2425You can use a `ref` to change the initial countdown.26`start()` and `resume()` also accept a new countdown value for the next countdown.2728```ts29import { useCountdown } from '@vueuse/core'30import { shallowRef } from 'vue'3132const countdown = shallowRef(5)33const { start, reset } = useCountdown(countdown, {34})3536// change the countdown value37countdown.value = 103839// start a new countdown with 2 seconds40start(2)4142// reset the countdown to 4, but do not start it43reset(4)4445// start the countdown with the current value of `countdown`46start()47```4849## Type Declarations5051```ts52export interface UseCountdownOptions extends ConfigurableScheduler {53/**54* Interval for the countdown in milliseconds. Default is 1000ms.55*56* @deprecated Please use `scheduler` option instead57*/58interval?: MaybeRefOrGetter<number>59/**60* Callback function called when the countdown reaches 0.61*/62onComplete?: () => void63/**64* Callback function called on each tick of the countdown.65*/66onTick?: () => void67/**68* Start the countdown immediately69*70* @deprecated Please use `scheduler` option instead71* @default false72*/73immediate?: boolean74}75export interface UseCountdownReturn extends Pausable {76/**77* Current countdown value.78*/79remaining: ShallowRef<number>80/**81* Resets the countdown and repeatsLeft to their initial values.82*/83reset: (countdown?: MaybeRefOrGetter<number>) => void84/**85* Stops the countdown and resets its state.86*/87stop: () => void88/**89* Reset the countdown and start it again.90*/91start: (countdown?: MaybeRefOrGetter<number>) => void92}93/**94* Reactive countdown timer in seconds.95*96* @param initialCountdown97* @param options98*99* @see https://vueuse.org/useCountdown100*/101export declare function useCountdown(102initialCountdown: MaybeRefOrGetter<number>,103options?: UseCountdownOptions,104): UseCountdownReturn105```106