I'm making a shopping cart. I want to show the price of each product based on their quantity. I made the buttons to add or subtract the quantity of products. However the quantity changes in all products because they all share the same data. How can I do to change quantity for the specific product?
<div v-for="(cartProduct,index) in cartProducts" :key="index" class="px-3 py-2">
<div id="cartProducts">
<p>{{cartProduct.description}}</p>
<button @click="subtract" >-</button> <p>{{quantity}}</p> <button @click="add">+</button>
<p>$ {{cartProduct.price*quantity}}</p>
</div>
</div>
export default {
data(){
return{
quantity:1
}
},
methods:{
add(){
this.quantity++;
},
subtract(){
this.quantity--;
},
}