Skip to content

Instantly share code, notes, and snippets.

@the94air
Forked from techlab23/mutations.js
Created June 27, 2018 17:00
Show Gist options
  • Save the94air/ddfc03dbe465fdbfc7941e269914e852 to your computer and use it in GitHub Desktop.
Save the94air/ddfc03dbe465fdbfc7941e269914e852 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 = {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment