美文网首页
2021-04-30 vue中定时器setInterval使用

2021-04-30 vue中定时器setInterval使用

作者: 半眼鱼 | 来源:发表于2021-04-30 15:27 被阅读0次
      destroyed() {
        clearInterval(this.positionTimer)// 清除定时器
        this.positionTimer = null
        // 离开路由之后断开websocket连接
        this.webSocketOnClose()
        this.websocketclose()
      },
      methods: {
        // 添加定时器
        addSetInterval() {
          const that = this  // 声明一个变量指向vue实例this,保证作用域一致
          this.positionTimer = setInterval(() => {
            if (that.resultArr.length < that.times) {
              clearInterval(that.positionTimer)
              that.positionTimer = null
              console.log(that.times)
            } else {
              // 分批部署基站
              if (that.times < that.resultArr.length) {
                that.deployBaseStation()
                console.log('渲染数组的第' + that.times + '项')
              }
              that.times++
            }
            console.log(1111111111111)
          }, 500)
        },
    
    

    相关文章

      网友评论

          本文标题:2021-04-30 vue中定时器setInterval使用

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