|
@@ -29,11 +29,17 @@ export default {
|
|
|
data() {
|
|
|
return {
|
|
|
tableData: [],
|
|
|
- nowDate: ''
|
|
|
+ nowDate: '',
|
|
|
+ intervalId: null
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
this.getList()
|
|
|
+ this.dataRefreh()
|
|
|
+ },
|
|
|
+ destroyed(){
|
|
|
+ // 在页面销毁后,清除计时器
|
|
|
+ this.clear();
|
|
|
},
|
|
|
methods: {
|
|
|
getList() {
|
|
@@ -58,7 +64,24 @@ export default {
|
|
|
}
|
|
|
const nowDate = year + "-" + month + "-" + day;
|
|
|
this.nowDate = nowDate
|
|
|
- }
|
|
|
+ },
|
|
|
+ // 定时刷新数据函数
|
|
|
+ dataRefreh() {
|
|
|
+ // 计时器正在进行中,退出函数
|
|
|
+ if (this.intervalId != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 计时器为空,操作
|
|
|
+ this.intervalId = setInterval(() => {
|
|
|
+ console.log("刷新" + new Date());
|
|
|
+ this.getList(); //加载数据函数
|
|
|
+ }, 1000*60*10);
|
|
|
+ },
|
|
|
+ // 停止定时器
|
|
|
+ clear() {
|
|
|
+ clearInterval(this.intervalId); //清除计时器
|
|
|
+ this.intervalId = null; //设置为null
|
|
|
+ },
|
|
|
}
|
|
|
}
|
|
|
</script>
|