Closed
Description
Hi,
In my project's folder structure I splitted my Vuex actions (and also mutations, getters and state) into separate files, like suggested here.
Here is an example of an action.js file:
export const saveUserLog = ({ commit, rootState }, data) => {
data.user = rootState.globalModule.userConnected._id
commit('addUserLogToTempMemory', data)
this.$socket.emit('saveUserLog', data) // this doesn't work
}
How can I access to the $socket instance from within my action ?
I tried
export const saveUserLog = ({ commit, rootState, Vue }, data) => { // adding Vue here
data.user = rootState.globalModule.userConnected._id
commit('addUserLogToTempMemory', data)
Vue.$socket.emit('saveUserLog', data) // to access from here
}
and like suggested in this post
export const saveUserLog = ({ commit, rootState }, data) => {
data.user = rootState.globalModule.userConnected._id
commit('addUserLogToTempMemory', data)
this._vm.$socket.emit('saveUserLog', data) // doesn't work
}
Can you help me?
Thanks