So to explain why I need to do that : I've got a masonry of photos and I need to add an index to each of those photos.
The thing is I can't relie on the index of my v-for because sometimes it is on purpose an "empty case".
|---|---|---|
| | 2 | 3 |
| 1 |---|---|
| | 4 | 5 |
|---|---|---|
| 6 | | 8 |
|---| 7 |---|
| 9 | | 10|
|---|---|---|
The code looks like this.
<div v-for="(row, i) in rphotos" :key="i">
<div v-for="(p, j) in row" :key="i*nbCol+j">
<div v-if="p"
:data-index="index"
class="g-item">
<!-- Increment index there -->
</div>
<div v-else class="g-item g-empty" />
</div>
</div>
However due to vuejs reactivity, my index will always be updated.
An other solution could perhaps be to check through a computed if on the row, g-item
is not too a g-empty
however I'm not even sure it is possible and yet dont see how precisely I could do this.
My best bet would be to increment a value on display as it is done in PHP template rendering like Smarty or Blade. But since javascript frameworks is meant to be reactive is there a way of doing that ?
Any idea is welcomed.