Created
March 1, 2018 05:33
-
-
Save techlab23/6979ecae784daef8a86d0e4a89f4b321 to your computer and use it in GitHub Desktop.
Vuex mutations with add, edit and delete entries
This file contains hidden or 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
Thanks. That helped a lot.