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

socket with vuex not work #41

Closed
Caraws opened this issue Mar 24, 2017 · 3 comments
Closed

socket with vuex not work #41

Caraws opened this issue Mar 24, 2017 · 3 comments

Comments

@Caraws
Copy link

Caraws commented Mar 24, 2017

On Server

io.on('connection', function(socket){
  console.log('a user connected');
  socket.on('disconnect', function(){
      console.log('user disconnected');
  });

  socket.emit("SOCKET_USER_MESSAGE",'hi');

  socket.on('emit_method', function(data){
      console.log(data);
  });
});

On Vuex

SOCKET_CONNECT : (state,status) => {
		state.connect = true;
		alert('connect with socket.io')
	},
	SOCKET_USER_MESSAGE : (state,message) => {
		alert(message)
		state.newMessage = message
	}

connect is success, but i can't get message.

And in this way,it's work

sockets: {
            SOCKET_USER_MESSAGE : function (data) {
                console.log(data)
            }
        }

What did I do wrong ??

@MetinSeylan
Copy link
Owner

io.on('connection', function(socket){
  console.log('a user connected');
  socket.on('disconnect', function(){
      console.log('user disconnected');
  });

  socket.emit("USER_MESSAGE",'hi'); // "SOCKET_" prefix is only client side

// or   socket.emit("user_message",'hi');

  socket.on('emit_method', function(data){
      console.log(data);
  });
});

@Caraws
Copy link
Author

Caraws commented Mar 25, 2017

thx!! it's work~

@Caraws
Copy link
Author

Caraws commented Mar 28, 2017

i have other question...
in IE11
[Vue warn]: Error in beforeCreate hook: (found in <xxx>)
only on IE11

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