I have a shopping cart which is an array of products and I want to access each name in the cart. I have a forEach function in getters but it only returns a name. I tried .map() but it returns another array and I need multiple string values. can you help?
let cart = window.localStorage.getItem('cart') const store = createStore({ state: { cart: cart ? JSON.parse(cart) : [], }, getters: { setTitle: state =>{ let oneItem='' state.cart.forEach((item)=>{ oneItem=item.ropeTitle }) return oneItem }, } }
This is because you only returned
oneItem
(let me guess, it was also the last item in thestate.cart
array?)You can try using
.join()
to join the items together.Suppose you want to use
,
to connect projects, you can try