Skip to content

Instantly share code, notes, and snippets.

/main.js Secret

Created January 17, 2018 14:18
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/fa93b7411fa1a4795b1b866111bcb7f3 to your computer and use it in GitHub Desktop.
Save anonymous/fa93b7411fa1a4795b1b866111bcb7f3 to your computer and use it in GitHub Desktop.
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vuex from 'vuex'
import VueSocketio from 'vue-socket.io'
import counterModule from './modules/counterModule'
Vue.use(Vuex)
Vue.config.productionTip = false
const store = new Vuex.Store({
state: {
io: {}//rootState.io
},
mutations: {
setSocket: (state, socket) => {
state.io = socket
console.log('socket connected')
}
},
modules: {
counterModule
}
})
Vue.use(VueSocketio, 'http://localhost:5000', store)
new Vue({
el: '#app',
router,
store,
//en cada carga, definimos un socket para este cliente
beforeCreate () {
store.commit('setSocket', this.$socket)
},
template: '<App/>',
components: { App }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment