data中:
data () {
return {
timer: null // 定时器
}
},
进入页面调用方法
onShow() {
let that = this
this.onDevDetails()
this.timer = setInterval(function() {
that.onDevDetails()
}, 3000)
},
离开页面销毁(跳转下一页)
onHide() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
},
返回上一页停止调用
onUnload() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
},