I have a getVueItems mehod that return products:

getVueItems: function(page){
   axios.get('./api/home/product').then(response => {
     this.items = response.data;
   });
},



<div v-for="item in items" :key="item.id">
 .
 .
 .
 <a @click="AddCart()"></a>
</div>

as you see i have a another method that name is AddCart, this method is independent and must running a unique url to add the item to cart:

AddCart() {
    axios.get( `./add-to-card/1`)
    .then((response) => {
        this.$store.dispatch('CartDetail')
    });
},

in AddCart() axios url i need to get the id of product,how can i do this?

1 Answers

0
Christophe Marois On Best Solutions

You have access to item in the scope of your v-for tag/block. Just do <a @click="AddCart(item.id)"></a>, and receive the argument with AddCart(id) {}