I have the following Vue template:
<div v-for="cartItem in cartItems">
<p class="is-size-5 has-text-weight-bold" v-if="showCategoryName(cartItem.searchCat2)">
{{cartItem.searchCat2}}
</p>
</div>
Which is calling the following Vue method
showCategoryName(catName) {
if (this.currentCatName === catName) {
return false;
}
this.currentCatName = catName;
return true;
},
This causes the following Vue Warning in the console:
You may have an infinite update loop in a component render function.
As you can see by the code, although there is assignment in the loop, there is nothing about this assignment that will cause infinite updates.
I have also tried replacing {{cartItem.searchCat2}}
with {{currentCatName}}
but I still receive the error.
How can I either suppress this error, or make Vue satisfied that there is no infinite update loop possible?
Update:
What this code accomplishes for me is that, because cart items are grouped by category name, only the first item with that category name displays the category name. So instead of every product of the chair category having "Chair" displayed above it, only the first does. This works as I expect it to.
showCategoryName
do by settingcurrentCatName
? (Template rendering should be idempotent...) - Ry-true
, but then you change it tofalse
? In the end you would show nothing? - dzirafv-if
into somemap()
ed version ofcartItems
. That way you are doing as little logic within thev-for
as possible. - zero298