页面更改后,setInterval正在运行

时间:2018-10-22 18:44:25

标签: javascript reactjs typescript

我的函数有问题,在页面更改后,函数继续运行并且出现错误,如何停止它,谢谢

 componentDidMount() {
    var current = 0;
    var slides = document.getElementsByClassName("j1");

    setInterval(function() {
          let rec = window.location.href;
          rec = rec.split('/');
          console.log(rec);

          for (var i = 0; i < slides.length; i++) {
            slides[i].style.opacity = 0;
            for (var j = 0; j < 10000; j++) {
              let k = j;
            }

          }
          current = (current != slides.length - 1) ? current + 1 : 0;
          slides[current].style.opacity = 1;

    }, 5000);
    } 

1 个答案:

答案 0 :(得分:3)

您必须注销间隔时间。像这样:

if indexPath.row == 0
{
    performSegue(withIdentifier: "gamelist", sender: nil)
}
else if indexPath.row == 1
{
    performSegue(withIdentifier: "leaderboard", sender: nil)
}
else if indexPath.row == 2
{
    performSegue(withIdentifier: "IGL_STORE", sender: nil)
}
else if indexPath.row == 3
{
    performSegue(withIdentifier: "event", sender: nil)
}
else if indexPath.row == 4
{
    performSegue(withIdentifier: "IGLNews", sender: nil)
}
else if indexPath.row == 5
{
    performSegue(withIdentifier: "IGL_TV", sender: nil)
}
else if indexPath.row == 6//HOW TO PLAY
{
    // performSegue(withIdentifier: "IGL_Store", sender: nil)
}