dispatch an action
-> action commit a mutation
-> mutation modify state
-> getter return state
this.$store.dispatch("moveToSecondArray", element);
state: {
firstArray: [{id: 1, name: 'User 1'},
{id: 2, name: 'User 2'},
{id: 3, name: 'User 3'},
],
}
firstArray(state) {
return state.firstArray
}
moveToFirstArray(context, element) {
context.commit('moveToFirstArray', element);
}
moveToFirstArray(state, element) {
state.firstArray.push(element);
state.secondArray.splice(state.secondArray.indexOf(element), 1);
}
npm install
npm run serve