vue中setTimeout定时器的使用
created() {
if (this.timer) {
clearTimeout(this.timer)
}
this.getCount()
},
methods: {
// 定时器(每隔一分钟获取一次状态)
getCount() {
this.getrealtime()
let _this = this
this.timer = setTimeout(() => {
_this.getCount()
}, 60000)
}
},
beforeDestroy() {
clearTimeout(this.timer)
}
还没有评论,来说两句吧...