I'm trying to get ID from specific element. But the data is returning as many elements as there are and all are same value. Even if I click another element button, the value was unchanged.The output Screenshot How I resolve this?
Here parent component code:
<template>
<ProductsList
class="w-full"
:product="item"
@product-id="selectedID"
v-for="(item, idx) in products"
:key="idx"
/>
</template>
<script>
export default {
async asyncData(context) {
const products = await context.app
.$axios({
method: "get",
url: process.env.PROJECT_API + "/products",
headers: {
Authorization: `Bearer ${context.store.state.currentToken}`,
},
})
.then((res) => res.data.products);
return {
products,
};
},
methods: {
selectedID(id) {
this.products.find( el => {
el._id === id
console.log({id});
})
}
},
}
</script>
The child component code:
<template>
<button @click="passId">
details
<button>
<template>
export default {
props: ['product'],
methods: {
passId() {
this.$emit('product-id', this.product._id)
}
},
}
</script>