Encountered an issue with the findIndex()
function
Uncaught (in promise) TypeError: state.carts.findIndex is not a function
The cartId includes rowId, qty, sizeVal, and image
Methods
updateCart() {
this.$store.dispatch('updateCart', this.cartId)
}
State
state: {
carts: [],
},
Vue Inspect Carts
031e0275ef3746070e80d81199bd2580:Object {
id:1
name:"T-Shirt"
options:Object {
image:"products\July2018\4TXSMgf6eAdrOlaxAMiX.jpg"
}
size:"l"
price:551
qty:2
rowId:"031e0275ef3746070e80d81199bd2580"
subtotal:1102
tax:115.71
}
mutations
updateCart(state, rowId) {
const index = state.carts.findIndex(cart => {cart.rowId == rowId});
// console.log(index)
state.carts.splice(index, 1, {
'qty': cart.qty,
'size': cart.sizeVal,
})
},
Action is functioning correctly
Actions
updateCart(context, cart) {
return new Promise((resolve, reject) => {
axios.patch(`update/cart/${cart.id}` , {
id: cart.rowId,
qty: cart.qty,
size: cart.sizeVal,
image: cart.image
})
.then(response => {
context.commit('updateCart', response.data)
resolve(response)
})
.catch(error => {
reject(error)
})
})
},
Looking to resolve the error encountered while updating state.carts
Your assistance on resolving this issue will be greatly appreciated
Thank you