在for循环完成后设置回值



我有以下代码有问题。

在我的模板中单击我的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
}
}

您不希望方法returnthis.counter = 0

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

最新更新