Skip to content

Commit

Permalink
feat: 完善倒计时生命周期
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhenfei committed Sep 28, 2020
1 parent 9540b6b commit c5be002
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/pi-count-down/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,18 @@ export default {
}
}
},
beforeDestroy() {
clearInterval(this.timer)
this.timer = null
},
methods: {
run() {
// 避免可能出现的倒计时重叠情况
this.clearTimer()
if (this.timestamp <= 0) return
this.timer = setInterval(() => {
this.val--
this.handleEmitChange()
if (this.val <= 0) {
return this.stop()
}
Expand Down

0 comments on commit c5be002

Please sign in to comment.