I'm facing a challenge with using indexOf inside a vuex mutation when calling an action that returns a promise. Here is the action code:
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)
})
})
}
Here is the mutation code:
[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)
}
I encountered an error saying "indexOf is not a function." Can anyone explain why this might be happening?