I've been working on a Vue project where I'm implementing a shopping cart feature. In this setup, when the user clicks on a button, the item details are stored in localStorage and then displayed in the shopping cart interface.
However, I encountered an issue where pressing on a new product to add it to the cart resulted in my key being overwritten. Consequently, I could only have one item in the cart at a time.
Snippet of relevant code:
addToCart() {
var size = this.selectedSize;
var color = this.selectedColor;
let newItem = {size: size, color: color, name: this.getProductDetails(this.productLinks).name, id: this.getProductDetails(this.productLinks).id};
this.cartItems.push(newItem);
localStorage.setItem(CART_STORAGE_KEY, JSON.stringify(this.cartItems));
}