# Countdown
> Countdown with optional controls.
## Basic usage
```html
<template>
<vue-countdown :time="2 * 24 * 60 * 60 * 1000" v-slot="{ days, hours, minutes, seconds }">
Time Remaining:{{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }} seconds.
</vue-countdown>
</template>
```
## Custom interval
```html
<template>
<vue-countdown :time="time" :interval="100" v-slot="{ days, hours, minutes, seconds, milliseconds }">
New Year Countdown:{{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }}.{{ Math.floor(milliseconds / 100) }} seconds.
</vue-countdown>
</template>
<script>
export default {
data() {
const now = new Date();
const newYear = new Date(now.getFullYear() + 1, 0, 1);
return {
time: newYear - now,
};
},
};
</script>
```
## Transform slot props
```html
<template>
<vue-countdown :time="2 * 24 * 60 * 60 * 1000" :transform="transformSlotProps" v-slot="{ days, hours, minutes, seconds }">
Time Remaining:{{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }} seconds.
</vue-countdown>
</template>
<script>
export default {
methods: {
transformSlotProps(props) {
const formattedProps = {};
Object.entries(props).forEach(([key, value]) => {
formattedProps[key] = value < 10 ? `0${value}` : String(value);
});
return formattedProps;
},
},
};
</script>
```
## Countdown on demand
```html
<template>
<button type="button" class="btn btn-primary" :disabled="counting" @click="startCountdown">
<vue-countdown v-if="counting" :time="60000" @end="onCountdownEnd" v-slot="{ totalSeconds }">Fetch again {{ totalSeconds }} seconds later</vue-countdown>
<span v-else>Fetch Verification Code</span>
</button>
</template>
<script>
export default {
data() {
return {
counting: false,
};
},
methods: {
startCountdown: function () {
this.counting = true;
},
onCountdownEnd: function () {
this.counting = false;
},
},
};
</script>
```
## Props
| Name | Type | Default | Options | Description |
| --- | --- | --- | --- | --- |
| auto-start | `boolean` | `true` | - | Indicate if starts the countdown automatically when initialized or not. |
| emit-events | `boolean` | `true` | - | Indicate if emits the countdown events or not. |
| interval | `number` | `1000` | - | The interval time (in milliseconds) of the countdown progress. The value should not be less than `0`. |
| now | `Function` | `() => Date.now()` | - | Generates the current time (in milliseconds) in a specific time zone. |
| tag | `string` | `"span"` | - | The tag name of the component's root element. |
| time | `number` | `0` | - | The time (in milliseconds) to count down from. |
| transform | `Function` | `(slotProps) => slotProps` | - | Transforms the output slot props before render. The `slotProps` object contains the following properties: `days`, `hours`, `minutes`, `seconds`, `milliseconds`, `totalDays`, `totalHours`, `totalMinutes`, `totalSeconds`, and `totalMilliseconds`. |
## Methods
| Name | Parameters | Description |
| --- | --- | --- |
| start | `()` | Starts the countdown. Run automatically when the `auto-start` prop is set to `true`. |
| abort | `()` | Aborts the countdown immediately. |
| end | `()` | Ends the countdown manually. |
| restart | `()` | Restarts the countdown. |
## Events
| Name | Parameters | Description |
| --- | --- | --- |
| start | `()` | Fires immediately when the countdown starts. |
| progress | `(data)` | Fires continually when the countdown is in progress. The `data` object contains the following properties: `days`, `hours`, `minutes`, `seconds`, `milliseconds`, `totalDays`, `totalHours`, `totalMinutes`, `totalSeconds`, and `totalMilliseconds`. |
| abort | `()` | Fired when the countdown has aborted. |
| end | `()` | Fired when the countdown has ended. |
> Native events that bubble up from child elements are also available.
**Note:** You can set the `emit-events` property to `false` to disable these events for better performance.
徐浪老师
- 粉丝: 8550
- 资源: 1万+
最新资源
- springboot基于协同过滤算法的黔醉酒业白酒销售系统_p091v--论文-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 基于CGAN网络的二维码图像生成技术研究与实现
- 431大神PHP基于MVC三层酒店预订管理系统毕业课程源码设计
- springboot基于Spark的共享单车数据存储系统的设计与实现_71220--论文-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- springboot基于hive旅游数据的分析与应用_4x1c2--论文-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- springboot基于Web的铁路订票管理系统_w8iq4-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 计算机毕业设计Java实现的智能二维码门禁管理系统源码+论文资料
- springboot档案管理系统_8xpgg--论文-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- nash-m-02结果.7z
- springboot+vue办公管理系统-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- springcloud房产销售平台-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- Java高校党支部党务管理系统-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
- 基于龙芯的智能识别系统设计3:Python-Opencv边缘检测,输出坐标像素点
- 永磁同步电机非线性磁链观测器-示例代码 介绍: 1.该算法是对传统三段式启动方法(定位-强拖-闭环)的全新升级,可以实现零速闭环直接启动 相比三段式启动,代码大大简化 2.对于轻载启动,如风机,水
- 2025-01-07 11-24-25 的屏幕截图.png
- springboot大学生活动社团管理系统(完整运行版本)-springboot毕业项目,适合计算机毕-设、实训项目、大作业学习.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈