I have a Parent.vue, where i send an object to a Child component, and get back the updated item every now and then via this.$emit('updateItem', item).
<template>
<div>
<Child
v-for="(item, index) in items"
:key="index"
:item="item"
@updateItem="updateItem"
// @updateItem="updateItem(index, dataFromChildComponent)" // this is what i would like to do
/>
</div>
</template>
<script>
export default {
name: 'Parent',
data() {
return {
items: [] // List of objects
}
},
methods: {
updateItem (index, data) {
// Receive the data and the index
}
}
}
</script>
The problem i keep running into is how to locate the object in the list of items in the Parent to update the correct one. I would like to enrich this data to add e.g. an index to be able to locate the item in the list.
Is there any way to achieve this or is it actually the correct way to propagate the index down to the Child in order to emit it back up again? Feels like an anti-pattern to me.