Skip to content

useStopwatch

Stopwatch counting up from zero. The elapsed time is recomputed from timestamps on every tick, so it does not accumulate interval drift while running. Pausing holds the elapsed time; resuming continues from where it stopped.

Demo

0
Years
0
Months
0
Days
0
Hours
0
Minutes
0
Seconds
0
Milliseconds

Usage

vue
<script setup>
import { useStopwatch } from "vue-countdown-composable";

const { minutes, seconds, isRunning, start, pause, resume, stop } =
  useStopwatch();
</script>

<template>
  <div>{{ minutes }}m {{ seconds }}s</div>
  <button @click="start(100)">start</button>
</template>

API

Returned values

All values are read-only and reactive.

NameTypeDescription
millisecondsComputedRef<number>Elapsed milliseconds (0–999)
secondsComputedRef<number>Elapsed seconds (0–59)
minutesComputedRef<number>Elapsed minutes (0–59)
hoursComputedRef<number>Elapsed hours (0–23)
daysComputedRef<number>Elapsed days (0–29)
monthsComputedRef<number>Elapsed months (0–11), approximated as 30 days
yearsComputedRef<number>Elapsed years, approximated as 12 × 30-day months
isRunningReadonly<Ref<boolean>>Whether the stopwatch is currently ticking

Methods

NameSignatureDescription
start(updateInterval?: number) => voidStart from zero, updating every updateInterval ms (default 1000; invalid values warn and fall back). Calling it again restarts from zero.
pause() => voidPause the stopwatch, holding the elapsed time.
resume() => voidResume a paused stopwatch from the held elapsed time. No-op if already running or stopped.
stop() => voidStop and reset the elapsed time to zero. A stopped stopwatch cannot be resumed — call start again.

Cleanup

The interval is cleared automatically when the owning component (or effectScope) is disposed — no manual cleanup needed.

Released under the MIT License.