vue数组中动态数字递增(从0到指定值)

我们需要准备一个数组,中有对象有数据,但数据都设置为0

还有一个数组是通过请求后台服务器获取到包含数据的数组

 我们需要用到定时器+递归

methods: {
    //   当页面挂载,从0开始递增
    move() {
      let timer = setInterval(() => {
        //   console.log('定时器循环')
         for(let index=0;index<this.dataList.length;index++)
          if (this.dataList[index].num < this.dataList2[index].num) {
            this.dataList[index].num++;
            this.move();
          } else {
            //   console.log('定')
            clearInterval(timer);
          }
        }, 30);
      
    }
  },
  mounted() {
    this.move();
  }

记住哈,这里尽量不要使用forEach哦,可能会出现卡顿的情况


版权声明:本文为guhanfengdu原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。