Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this._vm is undefined using Vuex modules #523

Closed
Kahss opened this issue Apr 6, 2021 · 4 comments
Closed

this._vm is undefined using Vuex modules #523

Kahss opened this issue Apr 6, 2021 · 4 comments

Comments

@Kahss
Copy link

Kahss commented Apr 6, 2021

Hi,

I can't find a way to make an emit from inside a socket action work. Here is my code

const actions = {
    socket_pseudoValid (state, pseudo) {
        state.commit('setValidPseudo', pseudo)
        this._vm.$socket.client.emit('ask_for_opp_list')
    },
]

This code is located is a vuex module. When I reach the emit line, vue devtools tells me that this._vm is undefined. Any idea ?

@probil
Copy link
Owner

probil commented Apr 6, 2021

Hey @D-Maurel
Could you provide a version of vuex/vue library you are using? Accessing this inside the module is not documented so it might be removed (or have already been removed)

I suggest checking approach (1) described here #91 (comment) as it will also work in any other places (not just outside vuex)

@Kahss
Copy link
Author

Kahss commented Apr 6, 2021

Hey @probil
Here is the return of npm list

├── vue-socket.io-extended@5.0.0-alpha.3
├── vue@3.0.7
└── vuex@4.0.0

If you have any new approach, I'm interested. In the meantime, i'll try the solutions you've linked, thank you !

EDIT : I've tried putting the socket definition in a separate file, but it works, thank you !

@probil
Copy link
Owner

probil commented Apr 6, 2021

Oh, I assume it's probably because of vuex 4 & vue 3. It doesn't use classes under the hood anymore. 🤔

@probil
Copy link
Owner

probil commented Apr 6, 2021

@D-Maurel let's close the issue if the solution works for you

@probil probil closed this as completed Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants