1、页面定时刷新
data() {
return {
intervalId: null,
}
},
mounted() {
this.renderInterval();
},
methods: {
renderInterval() {
if(this.intervalId != null) {
return ;
}
this.intervalId = serInterval(() => {
this.getDepsApi(); //调用刷新接口
},5000)
},
clear() {
clearInterval(this.intervalId);//清除计时器
this.intervalId = null; //设置为null
}
},
destroyed() {
this.clear();
}
2、时间会动
data() {
return {
curTime: moment().format('YYYY-MM-DD HH:mm:ss'),
}
},
mounted() {
this.timedUpdate();
},
method: {
timedUpdate() { //时间定时器
setInterval(() => {
this.curTime = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
},1000);
}
}