[Vuejs]-Element from array in props vue js

1👍

Based on the comments and also Michal Levý’s comment, I think what you are looking for is this:

<div class = 'bestsellers-item' v-for = '(item, index) in items': key = 'index'>
  <div class = 'bestsellers-item__sticker'>
    <img: src = 'item.img'>
  </div>
  <button @click="addCartItem(item.id)">Add to cart</button>
</div>

And then, your function:

addCartItem(itemId) {
    console.log("Do something with item " + itemId);
}

Leave a comment