0

当我使用带有承诺的动作时,我确实遇到了一些问题,让 vuex 突变中的 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 is not a function 有人知道为什么吗?

4

1 回答 1

0

我愚蠢到将 state.items 数组重新分配给代码中的对象,而 indexOf 函数消失了。

于 2016-11-15T16:33:33.423 回答