Skip to content
# t-count-down

CountDown 倒计时

t-count-down 组件介绍 ​

t-count-down 是一个倒计时组件,用于在界面上显示一个倒计时,可以自定义倒计时格式和持续时间。组件支持开始、暂停和继续倒计时,以及停止倒计时功能,适用于活动倒计时、商品促销倒计时、会议倒计时等场景。

t-count-down 平台兼容 ​

HarmonyH5AndroidiOS小程序UTS
✅✅✅✅✅✅

t-count-down 基础用法 ​

基础用法参考 demo/count-down/count-down.uvue,通过 time 属性设置倒计时时间(毫秒),通过 format 属性设置倒计时格式。

vue
<template>
	<view>
		<tui-theme-switch></tui-theme-switch>
		<t-card title="CountDown 倒计时"
				class="mlrt-15"
				sub-title="倒计时组件可展示倒计时,能自定义格式和时长。支持启停等操作,适用于活动等场景,支持插槽自定义显示。"></t-card>
		<introduction title="自定义样式">
			<t-count-down>
				5000000
				<template v-slot:default="{ times }">
					<t-row class="fl">
						<view class="bg-#f56c6c r-5 twh-25 fc">
							<text class="c-#fff">{{(times as UTSJSONObject)['hours']}}</text>
						</view>
						<text class="c-#f56c6c sfwb plr-5">:</text>
						<view class="bg-#f56c6c r-5 twh-25 fc">
							<text class="c-#fff">{{(times as UTSJSONObject)['minutes']}}</text>
						</view>
						<text class="c-#f56c6c sfwb plr-5">:</text>
						<view class="bg-#f56c6c r-5 twh-25 fc">
							<text class="c-#fff">{{(times as UTSJSONObject)['seconds']}}</text>
						</view>
					</t-row>
				</template>
			</t-count-down>
		</introduction>
		<introduction title="自定义样式">
			<t-count-down>
				5000000
				<template v-slot:default="{ times }">
					<t-row class="fl faic">
						<t-number mode='gl'>{{(times as UTSJSONObject)['hours']}}</t-number>
						<text class="sfwb mlr-10">:</text>
						<t-number mode='gl'>{{(times as UTSJSONObject)['minutes']}}</t-number>
						<text class="sfwb mlr-10">:</text>
						<t-number mode='gl'>{{(times as UTSJSONObject)['seconds']}}</t-number>
					</t-row>
				</template>
			</t-count-down>
		</introduction>
		<introduction title="自定义样式">
			<t-count-down>
				5000000
				<template v-slot:default="{ times }">
					<t-row class="fl faic">
						<t-number>{{(times as UTSJSONObject)['hours']}}</t-number>
						<text class="sfwb mlr-10">:</text>
						<t-number>{{(times as UTSJSONObject)['minutes']}}</t-number>
						<text class="sfwb mlr-10">:</text>
						<t-number>{{(times as UTSJSONObject)['seconds']}}</t-number>
					</t-row>
				</template>
			</t-count-down>
		</introduction>
		<introduction title="基础功能">
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c">50000</t-count-down>
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c"
						  type="primary">50000</t-count-down>
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c"
						  type="error">50000</t-count-down>
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c"
						  type="warning">50000</t-count-down>
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c"
						  type="success">50000</t-count-down>
		</introduction>
		<introduction title="自由控制">
			<t-count-down ref="tCountDowns"
						  class="r-10 mb-15 p-10 w-100% sta-c"
						  type="success">50000</t-count-down>
			<t-button class="mb-13"
					  type="primary"
					  @click="start">开始</t-button>
			<t-button class="mb-13"
					  type="error"
					  @click="pause">暂停</t-button>
			<t-button class="mb-13"
					  type="warning"
					  @click="continues">继续</t-button>
			<t-button class="mb-13"
					  type="success"
					  @click="stop">结束</t-button>
		</introduction>
		<introduction title="设置格式">
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c"
						  format="d天h时M分s秒">50000</t-count-down>
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c"
						  type="primary"
						  format="d天h时M分s秒">50000</t-count-down>
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c"
						  type="error"
						  format="d天h时M分s秒">50000</t-count-down>
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c"
						  type="warning"
						  format="d天h时M分s秒">50000</t-count-down>
			<t-count-down class="r-10 mb-15 p-10 w-100% sta-c"
						  type="success"
						  format="d天h时M分s秒">{{timers}}</t-count-down>
		</introduction>
	</view>
</template>
<script setup>
	const timers = ref<number>(50000)
	const tCountDowns = ref<ComponentPublicInstance | null>(null)
	function start() {
		tCountDowns.value?.$callMethod('start')
	}
	function pause() {
		tCountDowns.value?.$callMethod('pause')
	}
	function continues() {
		tCountDowns.value?.$callMethod('continues')
	}
	function stop() {
		tCountDowns.value?.$callMethod('stops')
	}
</script>

t-count-down Props ​

属性名说明类型默认值
path点击组件后跳转的页面路径;为空时仅响应事件string''
hover是否启用点击效果booleanfalse
type组件主题类型,可选 info、primary、error、warning、successstring''
disabled是否禁用booleanfalse
effect组件显示主题,可选 normal、dark、light、plainstring''
size组件尺寸,可选 large、medium、small、ministring''
time倒计时时间(毫秒)number0
format倒计时格式string'hh:MM:ss'
textClass文本样式any''

t-count-down Events ​

事件名说明回调参数
start开始倒计时时触发-
stop停止倒计时时触发-
pause暂停倒计时时触发-
continues继续倒计时时触发-
change倒计时变化时触发number
click点击时触发UniPointerEvent
initFinished组件初始化完成时触发,返回组件节点信息NodeInfo
touchstart触摸开始时触发-
touchend触摸结束时触发-
touchmove触摸移动时触发-
touchcancel触摸取消时触发-
transitionend动画结束时触发-

t-count-down Slots ​

插槽名说明
default默认插槽,用于自定义倒计时显示内容,提供 times 对象包含时、分、秒等信息