CountDown 倒计时
支持平台
安卓 | ios | web | 微信小程序 | 支付宝小程序 | QQ小程序 |
---|---|---|---|---|---|
√ | √ | √ | x | x | x |
示例
html
<template>
<t-page title="倒计时">
<t-card title="CountDown 倒计时" class="mlrt.30" sub-title="倒计时组件用于在界面上显示一个倒计时,可以自定义倒计时格式和持续时间。它的功能亮点包括:支持开始、暂停和继续倒计时,以及停止倒计时。使用场景包括:活动倒计时、商品促销倒计时、会议倒计时等。组件还提供了插槽,允许自定义倒计时显示内容。"></t-card>
<introduction title="基础功能">
<t-count-down class="mb.15" :time="50000"></t-count-down>
<t-count-down class="mb.15" :time="50000" type="primary"></t-count-down>
<t-count-down class="mb.15" :time="50000" type="error"></t-count-down>
<t-count-down class="mb.15" :time="50000" type="warning"></t-count-down>
<t-count-down class="mb.15" :time="50000" type="success"></t-count-down>
</introduction>
<introduction title="设置格式">
<t-count-down class="mb.15" :time="50000" format="d天h时M分s秒"></t-count-down>
<t-count-down class="mb.15" :time="50000" type="primary" format="d天h时M分s秒"></t-count-down>
<t-count-down class="mb.15" :time="50000" type="error" format="d天h时M分s秒"></t-count-down>
<t-count-down class="mb.15" :time="50000" type="warning" format="d天h时M分s秒"></t-count-down>
<t-count-down class="mb.15" :time="50000" type="success" format="d天h时M分s秒"></t-count-down>
</introduction>
<introduction title="自定义样式">
<t-count-down :time="5000000">
<template v-slot:default="{ hours,minutes,seconds }">
<t-row class="fl">
<view class="timers-sty">
<text class="txt">{{hours}}</text>
</view>
<text class="pl">:</text>
<view class="timers-sty">
<text class="txt">{{minutes}}</text>
</view>
<text class="pl">:</text>
<view class="timers-sty">
<text class="txt">{{seconds}}</text>
</view>
</t-row>
</template>
</t-count-down>
</introduction>
<introduction title="自由控制">
<t-count-down ref="tCountDown" class="mb.25" :time="50000" type="success"></t-count-down>
<t-button class="mb.25" type="primary" @click="start">开始</t-button>
<t-button class="mb.25" type="error" @click="pause">暂停</t-button>
<t-button class="mb.25" type="warning" @click="continues">继续</t-button>
<t-button class="mb.25" type="success" @click="stop">结束</t-button>
</introduction>
</t-page>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
start() {
const ins = this.$refs['tCountDown'] as ComponentPublicInstance
ins.$callMethod('start')
},
pause() {
const ins = this.$refs['tCountDown'] as ComponentPublicInstance
ins.$callMethod('pause')
},
continues() {
const ins = this.$refs['tCountDown'] as ComponentPublicInstance
ins.$callMethod('continues')
},
stop() {
const ins = this.$refs['tCountDown'] as ComponentPublicInstance
ins.$callMethod('stops')
}
}
}
</script>
<style lang="scss" scoped>
.pl {
color: #f56c6c;
font-weight: bold;
padding: 0 5rpx;
}
.timers-sty {
background-color: #f56c6c;
border-radius: 5rpx;
width: 50rpx;
height: 50rpx;
display: flex;
align-items: center;
justify-content: center;
.txt {
color: #fff;
}
}
</style>
Props
名称 | 描述 | 类型 | 默认值 | 可选值 |
---|---|---|---|---|
time | 倒计时时长,单位为秒 | Number | 0 | - |
format | 倒计时显示格式 | String | 'hh:MM:ss' | - |
Events
事件名 | 描述 | 回调参数 | 版本 |
---|---|---|---|
change | 倒计时变化时触发的事件 | (currentTime) |