After sending an array of data objects into a child component via props, I proceeded to use a v-for loop to display the elements exactly how I intended:
<div class="col-md-3" v-for="product in products" :key="product.id" v-if="product.id <= 8" >
<div>{{ product.name }}</div>
<button @click="buyProduct">
</div>
Following that, I implemented this method:
buyProduct(){
console.log('bought');
const order = {
orderId: this.product.id,
orderName: this.product.productName,
orderImg: this.produc.image,
orderOriginalPrice: this.product.originalPrice,
orderdiscountPrice: this.products.discountPrice,
orderQuantity: this.quantity,
};
console.log(this.products);
}
However, I encountered an error in the console stating: "TypeError: Cannot read property 'id' of undefined"
Any suggestions or solutions on how to retrieve the values of the clicked products would be greatly appreciated.