I need help finding a way to create a sequential counter for my nested loop. I attempted the following test:
<template>
<div class="container">
<ul>
<li v-for="item in list" :key="item">{{ counter++ }}</li>
</ul>
</div>
</template>
<script>
export default {
name: "Foo",
data() {
return {
list: ["item 1", "item 2", "item 3"],
counter: 0
};
}
};
</script>
Instead of returning 1,2,3, it displays as 303, 304, 305 and triggers this warning:
You may have an infinite update loop in a component render function.
I am aware that I can use (item, index)
. However, in my real code, I have a nested loop.
https://codesandbox.io/s/amazing-mcnulty-hou4p
This is an example of my actual situation with a nested loop:
<template v-for="ranking in daysImages[currentDay]['images']">
<template v-for="image in ranking">
<figure class="thumb"
v-for="path in image.paths"
:key="path"
@click="openModal()"
v-show="
(selectHashTag === allHashTagsTitle || image['hashtags'].includes(selectHashTag)) &&
(selectTag === allTagsTitle || image['tags'].includes(selectTag))"
>
<img :src="path | formatImageURL" alt="">
</figure>
</template>
</template>