I am trying to manage a simple shopping cart of products. The products are stored on the state as an array called items
export const state = () => ({
cart: {
items: [],
}
})
If a product is already been added to the cart, and someone tries to add it again, I'm trying to update the quantity field
addItem(state, product) {
let cartProduct = state.cart.items.find((item, index) => {
return item.id === product.id
})
cartProduct.quantity++;
});
This isn't working for me as it's not updating the state. Does anyone know the trick?