【问题标题】:set back value after for loop is completedfor循环完成后设置回值
【发布时间】:2021-10-15 09:39:09
【问题描述】:

我的以下代码有问题。

在我的模板中单击我的button 后,我的counter 将递增。现在我想检查我的counter 是否高于、低于或等于数组的length

在完成我的for-loops 之后,我想将我的counter 设置为零。

我已尝试使用 return this.counter = 0 - 但这不起作用。

提前感谢您帮助我!

methods: {
  if(this.counter > this.lengthArray) { 
    for(let i = this.lengthArray; i <= this.counter; i++) {
      //Do some code
    }
  } else if (this.lengthArray > this.counter) {
    for(let i = 1; i <= this.counter; i++) {
      //Do some code as well
    }
  } else if (counter == 0) {
    //Process another code
  }
},

data() {
  return {
    counter: 0
  }
}

【问题讨论】:

    标签: javascript vue.js for-loop vuejs2


    【解决方案1】:

    您不希望该方法将returnthis.counter = 0

    在最后一个条件之后设置 this.counter = 0 应该可以工作。什么都不应该返回或中断循环。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 2017-07-27
      • 1970-01-01
      • 2018-01-20
      • 2021-12-27
      相关资源
      最近更新 更多