zoukankan      html  css  js  c++  java
  • Angular-网页定时刷新

    类上方引入“OnInit”、“OnDestroy”

    import { OnInit, OnDestroy } from '@angular/core';

    类实现“OnInit”、“OnDestroy”

     类A implements OnInit, OnDestroy{
      ......
    }

    定时器代码方法

     ngOnInit() {
            this.now = new Date();
            this.startTime = new Date();
            this.runTimer();
        }
    
      //定时运行方法 runTimer() {
    this.nowInterval = setInterval(() => { if (this.startTime) { if (new Date().getTime() - this.startTime.getTime() > 60000) { console.log(this.now);                 this.getSearch(); } } this.now = new Date(); }, 1000); } ngOnDestroy() { clearInterval(this.nowInterval); }

      
    //查询页面数据
      getSearch(event?: LazyLoadEvent) {
          
          this.startTime = new Date();
          ........
      }
     
  • 相关阅读:
    web&http协议&django初识
    jQuery
    BOM&DOM
    装饰器
    JavaScript
    模块
    面向对象编程
    函数
    CSS
    HTML
  • 原文地址:https://www.cnblogs.com/jishugaochao/p/10456094.html
Copyright © 2011-2022 走看看