t-count-down
CountDown 倒计时
组件介绍
t-count-down 是一个倒计时组件,用于在界面上显示一个倒计时,可以自定义倒计时格式和持续时间。组件支持开始、暂停和继续倒计时,以及停止倒计时功能,适用于活动倒计时、商品促销倒计时、会议倒计时等场景。
平台兼容
| Harmony | H5 | Android | iOS | 小程序 | UTS |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
基础用法
基础用法参考 demo/count-down/count-down.uvue,通过 time 属性设置倒计时时间(毫秒),通过 format 属性设置倒计时格式。
vue
<template>
<!-- 基础倒计时 -->
<t-count-down :time="3600000" class="mb-30"></t-count-down>
<!-- 自定义格式倒计时 -->
<t-count-down :time="3600000" format="mm:ss" class="mb-30"></t-count-down>
<!-- 自定义显示样式 -->
<t-count-down :time="3600000" ref="countDownRef" class="mb-30">
<template #default="{ times }">
<view class="flex items-center">
<view class="w-30 h-30 bg-primary text-white rounded flex items-center justify-center mr-10">
{{ times.hh }}
</view>
<text class="text-20">:</text>
<view class="w-30 h-30 bg-primary text-white rounded flex items-center justify-center mx-10">
{{ times.MM }}
</view>
<text class="text-20">:</text>
<view class="w-30 h-30 bg-primary text-white rounded flex items-center justify-center ml-10">
{{ times.ss }}
</view>
</view>
</template>
</t-count-down>
<!-- 控制按钮 -->
<view class="flex space-x-20">
<t-button @click="pauseCountDown">暂停</t-button>
<t-button @click="continueCountDown">继续</t-button>
<t-button @click="stopCountDown">停止</t-button>
<t-button @click="startCountDown">开始</t-button>
</view>
</template>
<script setup>
const countDownRef = ref(null);
function pauseCountDown() {
countDownRef.value?.pause();
}
function continueCountDown() {
countDownRef.value?.continues();
}
function stopCountDown() {
countDownRef.value?.stops();
}
function startCountDown() {
countDownRef.value?.start();
}
</script>Props
| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
path | 点击组件后跳转的页面路径;为空时仅响应事件 | string | '' |
hover | 是否启用点击效果 | boolean | false |
type | 组件主题类型,可选 info、primary、error、warning、success | string | '' |
disabled | 是否禁用 | boolean | false |
effect | 组件显示主题,可选 normal、dark、light、plain | string | '' |
size | 组件尺寸,可选 large、medium、small、mini | string | '' |
time | 倒计时时间(毫秒) | number | 0 |
format | 倒计时格式 | string | 'hh:MM:ss' |
textClass | 文本样式 | any | '' |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
start | 开始倒计时时触发 | - |
stop | 停止倒计时时触发 | - |
pause | 暂停倒计时时触发 | - |
continues | 继续倒计时时触发 | - |
change | 倒计时变化时触发 | number |
click | 点击时触发 | UniPointerEvent |
initFinished | 组件初始化完成时触发,返回组件节点信息 | NodeInfo |
touchstart | 触摸开始时触发 | - |
touchend | 触摸结束时触发 | - |
touchmove | 触摸移动时触发 | - |
touchcancel | 触摸取消时触发 | - |
transitionend | 动画结束时触发 | - |
Slots
| 插槽名 | 说明 |
|---|---|
default | 默认插槽,用于自定义倒计时显示内容,提供 times 对象包含时、分、秒等信息 |