Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Reactjs中倒计时后重新启动计时器_Reactjs_Countdown_Antd - Fatal编程技术网

在Reactjs中倒计时后重新启动计时器

在Reactjs中倒计时后重新启动计时器,reactjs,countdown,antd,Reactjs,Countdown,Antd,我正在使用一个简单的计数器,弹出一个模式,然后在模式中的计时器达到零后再次关闭,我的问题是我不知道如何重新启动第一个计数器 希望你能理解我 谢谢 取出componentWillMount的内容并将其放入不同的函数中: componentWillMount() { this.foo(); } foo() { this.timer = setInterval(this.countDown, 1000); this.setState({ seconds: thi

我正在使用一个简单的计数器,弹出一个模式,然后在模式中的计时器达到零后再次关闭,我的问题是我不知道如何重新启动第一个计数器

希望你能理解我

谢谢


取出componentWillMount的内容并将其放入不同的函数中:

  componentWillMount() {
    this.foo();
  }

  foo() {
    this.timer = setInterval(this.countDown, 1000);
    this.setState({ seconds: this.props.time });
  }
然后,当间隔变为0时,必须调用此.foo():

  this.interval = setInterval(() => {
    this.setState({ currentCount: this.state.currentCount - 1 });
    if (this.state.currentCount === 0) {
      clearInterval(this.interval);
      this.setState({ visible: false });
      this.foo();
    }
  }, 1000);
  this.interval = setInterval(() => {
    this.setState({ currentCount: this.state.currentCount - 1 });
    if (this.state.currentCount === 0) {
      clearInterval(this.interval);
      this.setState({ visible: false });
      this.foo();
    }
  }, 1000);