Skip to content

CountDown

基础用法

html

<pa-count-down :time="1000 * 60 * 30" />

自定义格式

html

<pa-count-down :time="1000 * 60 * 60 * 26" format="DD天HH时mm分ss秒" />

毫秒级渲染

html

<pa-count-down :time="1000 * 60 * 30" format="HH:mm:ss:SSS" millisecond />

自定义样式

html

<pa-count-down :time="time" @change="onChange">
  <text class="time-item">{{ timeData?.hours }}</text>
  <text class="time-item">{{ timeData?.minutes }}</text>
  <text class="time-item">{{ timeData?.seconds }}</text>
</pa-count-down>
ts

import { ref } from 'vue'
import type { CountDownDuration } from '../../components'

const time = 1000 * 60 * 30
const timeData = ref<CountDownDuration>()

const onChange = (duration: CountDownDuration) => {
  timeData.value = duration
}

手动控制

html

<pa-count-down ref="countDownRef" :time="time" format="ss:SSS" millisecond :auto-start="false" />

<view class="flex mt-20">
  <pa-button @click="start">开始</pa-button>
  <pa-button class="ml-20" @click="pause">暂停</pa-button>
  <pa-button class="ml-20" @click="reset">重置</pa-button>
</view>
ts

import { ref } from 'vue'
import type { CountDownInstance } from '../../components'

const time = 1000 * 6
const countDownRef = ref<CountDownInstance>()

const start = () => {
  countDownRef.value?.start()
}

const pause = () => {
  countDownRef.value?.pause()
}

const reset = () => {
  countDownRef.value?.reset()
}

CountDown Props

参数说明类型默认值
time倒计时时长,单位毫秒number-
format时间格式,DD-日,HH-时,mm-分,ss-秒,SSS-毫秒string'HH:mm:ss'
autoStart是否自动开始倒计时booleantrue
millisecond是否开启毫秒级渲染booleanfalse

CountDown Event

事件名参数
finish()
change(duration: CountDownDuration)

CountDown Slot

名称说明
default-

样式变量

名称默认值
--pa-count-down-colorvar(--pa-color-black)
--pa-count-down-font-size14px
--pa-count-down-line-height20px