I am currently utilizing the pinia
library and I am seeking guidance on how to update a property within an object. Within my state.cart
, I have an array of objects representing various products, all of which contain a property named quantity
. As this quantity can be modified, I need to effectively "update" the cart data.
This is the approach I attempted:
state: () => ({
cart: []
}),
actions: {
updateQuantityOfProduct(product, val) {
const prod = this.cart.find((item) => item.id === product.id)
prod.quantity = val
this.$patch({
cart: this.cart,
})
},
}
However, it appears that this method does not yield the desired results. The cart remains unchanged, even after refreshing the page, indicating that the quantity of the product has reverted to its pre-change value.
What steps should I take to resolve this issue? Additionally, where might I be going wrong in my implementation?