Javascript vue findIndex不是函数

Javascript vue findIndex不是函数,javascript,vue.js,cart,vuex,Javascript,Vue.js,Cart,Vuex,这里我在findIndex()函数中得到了一个错误 Uncaught(in promise)TypeError:state.carts.findIndex不是函数 cartId具有rowId和qty以及sizeVal和image 方法 updateCart() { this.$store.dispatch('updateCart', this.cartId) } updateCart(state, rowId) { const index

这里我在
findIndex()函数中得到了一个错误

Uncaught(in promise)TypeError:state.carts.findIndex不是函数

cartId具有rowId和qty以及sizeVal和image

方法

    updateCart() {
        this.$store.dispatch('updateCart', this.cartId)
    }
    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: [],
},
检查手推车

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() {
        this.$store.dispatch('updateCart', this.cartId)
    }
    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)
            })
        })

    },
我的行动就是工作

行动

    updateCart() {
        this.$store.dispatch('updateCart', this.cartId)
    }
    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中更新carts的错误在哪里 需要帮助,伙计们,为什么会给我错误


谢谢

您的
状态。carts
是一个对象,而不是数组。
findIndex
是一个

方法返回数组中满足提供的测试函数的第一个元素的索引。否则返回-1


findIndex是ES6阵列功能,请确保您的浏览器支持它,或者您应该将polyfill或babel.js等透明文件插件应用到它。

将polyfill用作在Vue中全局导入的mixin

 const findIndex = (values, expectedValue) => {
    let selectedIndex;
    const valuePresent = values.some((value, index) => {
      selectedIndex = index;
      return value === expectedValue;
    });
    return valuePresent ? selectedIndex : -1;
  };

你能不能用文字代替图片。谷歌机器人不能真正抓取图像。我更喜欢图像,因为它是文档的截图。这证明我没有修改任何东西。报价单应该考虑到这一点,可能是通过文档链接的。介意我尝试编辑吗?请给我一个堆栈溢出指南的链接。如果它是正确的,我会更新。没有确切的指南说你不能添加图片,主要是为了让人们可以通过搜索引擎找到帖子。请务必引用重要链接中最相关的部分,以防目标站点无法访问或永久脱机。但我猜图像是oktest[]。在浏览器控制台上查找索引,如果它是一个函数,请检查数组的state.carts instanceof。