I've got this "basic" function which is checking if [i] element in array is the same as id:
checkArray(offer, id){
if (id)
{
this.count=0;
for (var i in offer.specialities) {
if (offer.specialities[i] == id)
{
console.log("bam!")
// this.count=+1;
return true;
break;
}
}
return false;
}
else {
return true;
}
},
variable count is declared in vuejs data
data() {
return {
count: 0
}
}
checkArray is called from v-show:
<v-layout row wrap v-for="offer in offers.slice((current_page-1)*5, current_page*5)"
v-show="checkArray(offer, speciality)">
at this point all works well. I've got two bams.
Now when I uncomment this.count=+1;
I've got 200 bams! and my vuejs console screams:
[Vue warn]: You may have an infinite update loop in a component render function.
Why is this happening? How can I count number of bams in variable?
for (i=0 in offer.specialities). You can havefor (i in offer.specialities), but not with=0.i=0 in offer.specialitieswhat should that do??;s in it.checkArrayis calledcheckArray? ... can you provide thetemplatepiece of your code? What is most probably happening is that usingthis.countin yourcheckArraymethod is mutating the state over and over again, causing the component to re-render every time.