Skip to content

CountDown

Used for verification code countdowns, event countdowns, payment time remaining, and order timeout scenarios.

Note

This component is implemented based on the useCountdown Hook, supporting precise wall-clock time calibration, millisecond-level precision, and custom formatting.

Platform Differences

App (vue)App (nvue)H5Mini Program

Basic Usage

  • Set the countdown duration (in milliseconds) via time.
  • The countdown starts automatically by default.
html
<see-count-down :time="60000" />

Custom Format

  • Customize the display format via format.
  • Supported placeholders: DD (days), HH/hh (hours), mm (minutes), ss (seconds), SSS (milliseconds).
html
<!-- Show minutes and seconds only -->
<see-count-down :time="120000" format="mm:ss" />

<!-- Show days -->
<see-count-down :time="86400000" format="DDd HH:mm:ss" />

Separator

  • Customize the separator via separator, defaults to :.
  • Only takes effect when format is not set.
html
<see-count-down :time="60000" separator="-" />
<see-count-down :time="60000" separator=" " />

Show Days

  • Set whether to show days via showDays, defaults to false.
html
<see-count-down :time="172800000" showDays />

Millisecond Precision

  • Enable millisecond-level precision display via millisecond.
html
<see-count-down :time="10000" millisecond />

Manual Control

  • Set autoStart to false to disable auto-start.
  • Manually control via component instance methods: start(), pause(), reset().
vue
<see-count-down ref="countdownRef" :time="60000" :autoStart="false" />
<button @tap="countdownRef?.start()">Start</button>
<button @tap="countdownRef?.pause()">Pause</button>
<button @tap="countdownRef?.reset()">Reset</button>

<script lang="ts" setup>
import { ref } from 'vue'
const countdownRef = ref()
</script>
vue
<see-count-down ref="countdownRef" :time="60000" :autoStart="false" />
<button @tap="$refs.countdownRef.start()">Start</button>
<button @tap="$refs.countdownRef.pause()">Pause</button>
<button @tap="$refs.countdownRef.reset()">Reset</button>

<script>
export default {
  data() {
    return {}
  }
}
</script>

Server Time

  • Pass the server timestamp via serverTime, used with endTime for precise cross-client countdowns.
html
<see-count-down :serverTime="1700000000000" :endTime="1700003600000" />

Slot Usage

  • The default slot exposes current time data for custom rendering.
html
<see-count-down :time="60000">
  <template #default="{ minutes, seconds }">
    <text>{{ minutes }}m {{ seconds }}s</text>
  </template>
</see-count-down>

Custom Styling

  • Set text color via textColor.
  • Set font size via fontSize.
  • Set block-level display via block.
html
<see-count-down :time="60000" textColor="#ff0000" fontSize="32rpx" />
<see-count-down :time="60000" block />

API

Props

ParameterDescriptionTypeDefaultOptional ValuesPlatform Notes
timeCountdown duration (ms)Number0Any non-negative integer-
formatCustom display formatString'' (auto: HH:mm:ss or DD:HH:mm:ss)String with DD/HH/mm/ss/SSS-
autoStartWhether to auto-start the countdownBooleantruetrue, false-
millisecondEnable millisecond precisionBooleanfalsetrue, false-
intervalCountdown interval (ms)Number0 (auto: 16ms for millisecond, 1000ms)Any positive integer-
serverTimeServer timestamp (ms)NumberundefinedAny timestamp-
endTimeEnd timestamp (ms)NumberundefinedAny timestamp-
separatorSeparator characterString':'Any string-
showDaysWhether to show daysBooleanfalsetrue, false-
zeroPadWhether to zero-pad numbersBooleantruetrue, false-
textColorText colorString'var(--see-text-color, #303133)'Any CSS color value-
fontSizeFont sizeString'28rpx'Any CSS font size value-
blockWhether to display as blockBooleanfalsetrue, false-

Events

EventDescriptionCallback ParametersPlatform Notes
onChangeTriggered on each countdown ticktimeData: { days, hours, minutes, seconds, milliseconds, total }-
onFinishTriggered when countdown finishesNone-
onStartTriggered when countdown startsNone-
onPauseTriggered when countdown pausesNone-
onResetTriggered when countdown resetsNone-

Slots

Slot NameDescriptionScope Data
defaultCustom display content{ days, hours, minutes, seconds, milliseconds, total, formatted }

Methods

Call via component instance obtained through ref.

MethodDescriptionParameters
startStart the countdownNone
pausePause the countdownNone
resetReset the countdowntime?: number Optional, reset to specified duration
finishImmediately finishNone

Liao ICP No. 2025070134