0

I am trying to call data from my Sockets object in a Vue component.

data() {
  return {
    message: []
  }
},
sockets: {
  chatMessage: data => {
    console.log(data); //-> my data from server
    console.log(this); //-> undefined 
    console.log(this.message); //-> Uncaught TypeError
  }
}

I'm successfully emitting and receiving the message event from the server because I'm getting data. But I don't know why I can't get the message prop from data.

Here are the docs from the library. https://github.com/MetinSeylan/Vue-Socket.io

1 Answer 1

1

The answer I found was to be that I was using fat arrow functions and so I wasn't binding this.

All I changed was:

sockets: {
  chatMessage: function(data){
    //-> returns what I needed
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.