I'm looking for a solution to create a sequencial counter for my nested loop. So I made this 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>
But instead return 1,2,3, it return 303, 304, 305 and this warning:
You may have an infinite update loop in a component render function.
I known that I can use (item, index). But I have a nested loop in real code.
https://codesandbox.io/s/amazing-mcnulty-hou4p
This is the real situation 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>
(item, index), since a nested loop shouldn't break it. The loop appears because you're doingcounter++in the actual rendering.data-indexattribute in<figure>tag(ranking, index),(image, index)or(path, index). None of them consider the entire loop.