Skip to content

Instantly share code, notes, and snippets.

@techlab23
Created March 1, 2018 05:33
Show Gist options
  • Save techlab23/6979ecae784daef8a86d0e4a89f4b321 to your computer and use it in GitHub Desktop.
Save techlab23/6979ecae784daef8a86d0e4a89f4b321 to your computer and use it in GitHub Desktop.
Vuex mutations with add, edit and delete entries
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 = {}
}
}
@the94air
Copy link

Thanks. That helped a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment