外面用
<template>
<keep-alive>
<view>代码</view>
</keep-alive>
</template>
data () {
return {
timer: null // 定时器
}
},
activated () {
this.timer = setInterval(() => {
// 定时器中执行的代码
}, 30000)
},
deactivated () {
// 页面关闭(路由跳转)时清除定时器
clearInterval(this.timer)
this.timer = null
},
methods: {
refresh(){
clearInterval(this.timer);
this.timer = null;
this.timer = setInterval(() => {
//定时器中执行的代码
this.getList();
}, 3000);
},
}