1.0.1 增加了时间到了的事件

This commit is contained in:
luo 2018-10-23 11:58:42 +08:00
parent 414b3dedcf
commit a63ae0000f
5 changed files with 22 additions and 10 deletions

View File

@ -25,10 +25,15 @@ import FlipDown from 'vue-flip-down';
### 参数
| 名称 | 类型 | 默认 | 描述 |
|----|----|----|----|
| ------- | ----------- | ---- | ------------------------------------------------------------------------------------- |
| endDate | Date/Number | 0 | 结束的时间即倒计时会从当前时间一直到endDate停止可以是一个日期对象也可以是毫秒数 |
| type | Number | 4 | 要怎么显示倒计时4-日时分秒3-时分秒2-分秒1-秒 |
### 事件
| 名称 | 返回值 | 描述 |
| ------ | ------ | --------------------------------------- |
| timeUp | null | 当倒计时走到0时会触发一次表示时间到了 |
### 说明

2
dist/main.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,8 @@
<template>
<div>
<CountDown :endDate="endDate"
:type="type" />
:type="type"
@timeUp="onTimeUp" />
<hr />
<input v-model="type">
@ -14,7 +15,7 @@ export default {
data() {
return {
type: 4,
endDate: new Date().getTime() + 100861100,
endDate: new Date().getTime(),
};
},
components: {
@ -24,6 +25,9 @@ export default {
onTypeChange(t) {
this.type = t;
},
onTimeUp() {
console.log('时间到了');
},
},
};
</script>

View File

@ -1,6 +1,6 @@
{
"name": "vue-flip-down",
"version": "1.0.0",
"version": "1.0.1",
"description": "vue 翻页效果的倒计时组件",
"main": "dist/main.js",
"scripts": {

View File

@ -139,7 +139,6 @@ export default {
//
start() {
clearTimeout(this.timer);
console.log('每秒1次啊');
this.timer = setTimeout(() => {
let t = this.endTime - new Date().getTime(); //
t = t < 0 ? 0 : t;
@ -169,7 +168,11 @@ export default {
this.min = String(min).padStart(2, '0');
this.second = String(second).padStart(2, '0');
if (t > 0) this.start();
if (t > 0) {
this.start();
} else {
this.$emit('timeUp');
}
}, 1000);
},
//