【发布时间】:2018-12-18 23:58:41
【问题描述】:
这里我在findIndex() 函数中遇到错误
Uncaught (in promise) TypeError: state.carts.findIndex is not a function
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,
})
},
在我的行动中是工作
操作
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 中更新购物车的错误 需要帮助,请大家了解一下为什么它给了我错误
谢谢
【问题讨论】:
标签: javascript vue.js cart vuex