Skip to content

Instantly share code, notes, and snippets.

@israeleriston
Last active May 7, 2017 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save israeleriston/a46307c540b603b3b22d65f66b835f92 to your computer and use it in GitHub Desktop.
Save israeleriston/a46307c540b603b3b22d65f66b835f92 to your computer and use it in GitHub Desktop.
//actions
export const resetMessages = ({ commit }) => {
commit(TYPES.SET_MESSAGE, { type: 'success', message: '' })
commit(TYPES.SET_MESSAGE, { type: 'error', message: [] })
commit(TYPES.SET_MESSAGE, { type: 'warning', message: '' })
commit(TYPES.SET_MESSAGE, { type: 'validation', message: [] })
}
// mutations
export default {
[TYPES.SET_MESSAGE_SUCCESS] (state, obj) {
state.messages.success = obj.message
},
[TYPES.SET_MESSAGE_VALIDATOR] (state, obj) {
state.messages.validation = obj.message
},
[TYPES.SET_MESSAGE_ERROR] (state, obj) {
state.messages.error = obj.message
},
[TYPES.SET_MESSAGE_WARNING] (state, obj) {
state.messages.warning = obj.message
}
}
// state
export default {
messages: {
validation: [],
warning: '',
success: '',
error: []
}
}
// beforeEach
export default (to, from, next) => {
store.dispatch('resetMessages')
if (!isLogged()) {
next('/auth')
} else {
next()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment