setInterval改成setTimeout

This commit is contained in:
蔡玲
2024-11-18 15:28:38 +08:00
parent 4defa75ef6
commit 521d51ea5c

View File

@@ -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) {