Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2018 14:07
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 anonymous/640ae42b66695ece5af27d9f3b250f9a to your computer and use it in GitHub Desktop.
Save anonymous/640ae42b66695ece5af27d9f3b250f9a to your computer and use it in GitHub Desktop.
Módulo con Vuex y Vue-Socket.IO
const counterModule = {
state: {
count: 0
},
//estas mutaciones serán ejecutadas por Node.js, deben comenzar por SOCKET_
mutations: {
SOCKET_COUNTER_INCREMENT (state) {
state.count = state.count + 1
},
SOCKET_COUNTER_DECREMENT (state) {
state.count = state.count - 1
}
},
//emitimos acciones desde nuestra app
actions: {
socket_increment: ({commit, state, rootState}) => {
rootState.io.emit('increment', state.count) //emitimos al server el evento increment
},
socket_decrement: ({commit, state, rootState}) => {
rootState.io.emit('decrement', state.count) //emitimos al server el evento decrement
}
}
}
export default counterModule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment