vue2-countdown-component
Version:
A Simple countdown component based on vue2
94 lines (72 loc) • 1.57 kB
Markdown
```
npm install vue2-countdown-component
```
```
<CountdownTimer ref="countdownRef" :duration="10">
<template
<span>头部插槽</span>
</template>
<template
<span>尾部插槽</span>
</template>
</CountdownTimer>
// main.js
import CountdownTimer from "vue2-countdown-component";
Vue.component("CountdownTimer", CountdownTimer);
```
```
<CountdownTimer ref="countdownRef" :duration="10">
<template
<span>头部插槽</span>
</template>
<template
<span>尾部插槽</span>
</template>
</CountdownTimer>
import CountdownTimer from "vue2-countdown-component";
export default{
components:{
CountdownTimer
}
}
```
```
duration: {
type: Number,
required: true,
default: 60,
}
```
| 序号 | 事件 | 描述 |
| ---- | ----- | ---------- |
| 1 | start | 倒计时开始 |
| 2 | end | 倒计时结束 |
| 3 | stop | 倒计时暂停 |
```
this.$refs.[ref].start(); // 开始
this.$refs.[ref].stop(); // 暂停
```
```
<countdown-timer ref="countdownRef" :duration="10"
@end="listenEnd" @stop="listenStop" >
</countdown-timer>
listenStop() {
this.msg = "倒计时已暂停";
},
listenEnd() {
this.msg = "倒计时已结束";
},
```
| 序号 | 事件 | 描述 |
| ---- | ------ | ---------------- |
| 1 | header | 自定义前面的内容 |
| 2 | footer | 自定义后面的内容 |