Carousel: stop timer before component destroyed (#13820)

Carousel: stop timer before component destroyed (#13820)
pull/13930/head
Harlan 2018-12-29 13:08:50 +08:00 committed by GitHub
commit 91c40d311e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -181,11 +181,14 @@ export default {
},
pauseTimer() {
clearInterval(this.timer);
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
},
startTimer() {
if (this.interval <= 0 || !this.autoplay) return;
if (this.interval <= 0 || !this.autoplay || this.timer) return;
this.timer = setInterval(this.playSlides, this.interval);
},
@ -257,6 +260,7 @@ export default {
beforeDestroy() {
if (this.$el) removeResizeListener(this.$el, this.resetItemPosition);
this.pauseTimer();
}
};
</script>