As Vuex, I\'m trying to update an object using form. My code like this.
In store:
const state = {
categories: []
};
//mutations:
[mutationType.UP
ES6 way of updating
//mutations UPDATE:
[mutationType.UPDATE_CATEGORY] (state, payload) {
state.categories = [
...state.categories.map(item =>
item.id !== updatedItem.id ? item : {...item, ...updatedItem}
)
]
}
//mutations CREATE:
[mutationType.CREATE_CATEGORY] (state, category) {
state.categories = [category, ...state.categories] //Append to start of array
}
//mutations DELETE:
[mutationType.DELETE_CATEGORY] (state, id) {
state.categories = [
...state.categories.filter((item) => item.id !== id)
];
}