In this CodeSandbox Demo, in child component (list.vue
) a list of p
tags, are rendered with v-for="(item, idx) in czCounter
.
Child component (with list in slot) in parent
<list>
<div class=cz-container>
<a @click="czCounter++" class="btn-add"> + </a>
<p v-for="(item, idx) in czCounter"
class="cz-item"
:key="idx"
:ref="`slide1zone`"
:czId="idx">
{{item}}
<a @click="deleteCurrentChildZone(idx)"class="btn-delete"> - </a>
</p>
</div>
</list>
When I call deleteCurrentChildZone
to remove the current p
tag and then mutate this.czCounter--
, two items are deleted from the list instead of the single/current p
tag.
I know el.remove()
might be unnecessary but I am more interested in knowing when el.remove()
and then parent’s property this.czCounter
is mutated (decremented) why does Vue deletes 2 items instead of one.
I am interested in learning what Vue is actually doing, when element is removed (el.remove()
) and this.czCounter
is mutated (decremented).
Thanks