export default {
  data(){
    return{
      timer:null,
    }
  },
  mounted () {
    this.queryInfo();
    this.timer = setInterval(() => {
      setTimeout(this.queryInfo, 0)
    }, 1000*60)
  },
  methods: {
    async queryInfo(){
      //do something
    },
  },
  beforeDestroy () {
    clearInterval(this.timer);
    this.timer = null;
  }

}

说明:
1.在执行定时器前先执行一次获取接口数据的操作函数, 否则接口会1分钟后才调用

2.为了避免退出当前页面后,在其他页面也继续调用接口,退出前需要清除定时器.

Logo

前往低代码交流专区

更多推荐