【小程序】setInterval定时执行与停止定时执行踩坑点

实现代码:

var timer = setInterval(function () {
            if (that.data.imageUrl != "false") {
              console.log(that.data.imageUrl);
              // 关闭定时循环
              clearInterval(that.data.interval);
            }
        },4000);

this.setData({
          interval: timer
         })
        

踩坑一:关闭循环为:clearInterval(that.data.interval);

踩坑二:function(){}  函数中不能使用this,否则会报   Cannot read property 变量 of undefined

猜你喜欢

转载自blog.csdn.net/qq_35808136/article/details/88654154