当action使用promise时,indexOf拒绝在值突变中工作

indexOf refuses to work inside vue mutation when action is using promise

本文关键字:突变 工作 拒绝 indexOf 使用 action promise      更新时间:2023-09-26

当我使用带有承诺的行动时,我确实得到了一些问题,使indexOf内部的性变变工作。这是我的动作

export const deleteItem = ({commit}, item) => {
    return new Promise((resolve, reject) => {
        Vue.http.delete(item.url, item)
           .then(response => {
               commit(types.DELETE_ITEM, {response, item})
               resolve(response)
           })
           .catch(error => {
               commit(types.ERROR, error)
               reject(error)
           })
    })
}

这是我的突变

[types.DELETE_ITEM](state, {response, item}) {
   state.notifications = {
            display:    true,
            type:       'success',
            ok:         response.ok,
            status:     response.status,
            statusText: response.statusText,
            body:       response.body
        }
        state.items.splice(state.items.indexOf(item), 1)
    }

我得到一个错误indexOf不是一个函数,有人知道为什么是这样吗?

我真蠢,重新分配了state。items数组到对象的代码和indexOf函数消失