-
-
Save the94air/ddfc03dbe465fdbfc7941e269914e852 to your computer and use it in GitHub Desktop.
Vuex mutations with add, edit and delete entries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import * as types from './mutation-types' | |
export default { | |
// Mutation to set entries in state | |
[types.SET_ENTRIES] (state, entries) { | |
state.entries = entries || {} | |
}, | |
// Mutation to add entry in state | |
[types.ADD_ENTRY] (state, payload) { | |
Vue.set(state.entries, payload.key, payload.data) | |
}, | |
// Mutation to add entry in state | |
[types.UPDATE_ENTRY] (state, payload) { | |
Vue.set(state.entries, payload.key, payload.data) | |
}, | |
// Mutation to add entry in state | |
[types.DELETE_ENTRY] (state, payload) { | |
Vue.delete(state.entries, payload.key) | |
}, | |
// Mutation to set user | |
[types.SET_USER] (state, result) { | |
state.user = result | |
}, | |
// Mutation to unset user | |
[types.UNSET_USER] (state) { | |
state.user = {} | |
state.entries = {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment