美文网首页
React使用定时器interval

React使用定时器interval

作者: 章鱼要回家 | 来源:发表于2019-11-12 09:53 被阅读0次

定义全局变量timer。

  timer = null;
  // 组件加载完毕 启动定时器
  componentDidMount(){
    setTimeout(this.iTimer,0);
  }

  // 组件清除时清除定时器
  componentWillUnmount(){
    clearInterval(this.timer);
  }

  // 定时器
  iTimer = () => {
    this.timer = setInterval(() => {
      this.handlereset;
    }, 1000);
  }

相关文章

网友评论

      本文标题:React使用定时器interval

      本文链接:https://www.haomeiwen.com/subject/yudfictx.html