diff --git a/pages/home/home.vue b/pages/home/home.vue index f607216..6dc2f9d 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -51,19 +51,25 @@ }, onLoad () { this._getBillsCount() - this.intervalId = setInterval(() => { - this._getBillsCount() - }, this.interTime) + this.timerFun(this._getBillsCount, this.interTime)() }, beforeDestroy () { - clearInterval(this.intervalId) - this.intervalId = null - }, - destroyed () { - clearInterval(this.intervalId) - this.intervalId = null + if (this.intervalId !== null) { + clearTimeout(this.intervalId) + this.intervalId = null + } }, methods: { + timerFun(f, time) { + let _this = this + return function backFun() { + clearTimeout(_this.intervalId) + _this.intervalId = setTimeout(function () { + f() + backFun() + }, time) + } + }, async _getBillsCount () { let res = await getBillsCount() if (res.code === 1) {