Do you see cartitems in the Vue Devtools in the browser ?
Sep 14, 2022
8
Level 1
state.cartitems.push is not a function at Store.setusercart
Am using Vue Js and am trying to add products to cart using Localstorage so that latter I can check them out. My code looks okay but am geting that error. Below is the code
state : {
cartitems: [],
},
getters : {
cartitems:(state )=> state.cartitems,
},
mutations : {
setusercart :(state,usercartitem ) => (state.cartitems.push(usercartitem)),
},
actions : {
async addstocktocart( { commit }, data) {
commit('seterror', '')
commit('setmsg'data. Titlele + 'has been added to Cart')
commit('setloader', 'addstocktocart')
commit('setusercart', data)
console.log(this.state.auth.usercartitems)
},
}
Please or to participate in this conversation.