Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- checkItem(state, item) {
- if (state.cart.length === 0) {
- state.cart.push(item)
- return
- }
- // Check if in the array the item exist
- // If it exist, foundItem === Object
- // Else, foundItem === undefined
- const foundItem = state.cart.find(c => c.id == item.id)
- // So if it found something
- // Print in the console
- // And return
- if(foundItem) {
- console.error('Item already found')
- return
- }
- // If it found nothing
- // Add it to the array
- state.cart.push(item)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement