I'm using pinia and I would like to know, how to update a property inside an object. I have an array of objects inside the state.cart, which are some products, which all have a property called quantity. This property can be changed, so I need to "update" the cart data.
This is what I've tried:
state: () => ({
cart: []
}),
actions: {
updateQuantityOfProduct(product, val) {
const prod = this.cart.find((item) => item.id === product.id)
prod.quantity = val
this.$patch({
cart: this.cart,
})
},
}
but this seems not to work, since the cart is not updated and/or when I refresh, the update/change has not been added (the quantity of the product is like before the change)
how can I solve this and what am I doing wrong?