这里在findIndex()
函数中出现了错误
Uncaught (in promise) TypeError: state.carts.findIndex不是一个函数
cartId具有rowId、qty、sizeVal和image属性
方法
updateCart() {
this.$store.dispatch('updateCart', this.cartId)
}
状态
state: {
carts: [],
},
Vue检查购物车
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
}
突变
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,
})
},
In my Action is work
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)
})
})
},
现在,我需要在state.carts中更新购物车,但出现了错误。请大家帮帮我,为什么会出现这个错误。
谢谢。