I have a basic application that retrieves data from an API and displays the array on the screen using a v-for loop.
The array is structured like this
items : [{id : 1, quantity: 2}, {id: 2, quantity: 3} ...]
The loop is set up like this
<div v-for="item in items" :key = "item.id">
<p>{{ item.name}} </p>
<button @click="updateQuantity(item.id)">Update Quantity</button>
</div>
I am attempting to change the quantity when a button is clicked, I'm using this function but even though the quantity is being updated, the updated value is not reflecting in the displayed quantity.
updateQuantity(id) {
// send a request to the API backend
this.$set(items[id], 'quantity', newQuantity)
console.log(this.items)
}
Even though the quantity is updated, the new value is not displayed on the page with the v-for loop, what could be the issue and how can I solve it?