vue前端定时刷新

如题所述

第1个回答  2022-06-10
data(){

    return {

        intervalId:null    }

},methods:{

  // 定时刷新数据函数    dataRefreh() {

      // 计时器正在进行中,退出函数      if (this.intervalId != null) {

        return;

      }

      // 计时器为空,操作      this.intervalId = setInterval(() => {

        console.log("刷新" + new Date());

        this.initData(); //加载数据函数      }, 5000);

    },

    // 停止定时器    clear() {

      clearInterval(this.intervalId); //清除计时器      this.intervalId = null; //设置为null    },

},created(){

    this.dataRefreh();

},destroyed(){

    // 在页面销毁后,清除计时器    this.clear();

}

原地址:https://www.cnblogs.com/aurora-ql/p/13300202.html
相似回答
大家正在搜