vue.js方法中是否未接收socket.io回调?
使用此vue.js方法登录用户:vue.js方法中是否未接收socket.io回调?,vue.js,callback,socket.io,Vue.js,Callback,Socket.io,使用此vue.js方法登录用户: loginUser: function () { socket.emit('loginUser', { email: this.email , password: this.password }, function() { console.log('rooms in callback are:', rooms); });
loginUser: function () {
socket.emit('loginUser', {
email: this.email ,
password: this.password
}, function() {
console.log('rooms in callback are:', rooms);
});
}
在服务器上,loginUser
事件由以下人员处理:
socket.on('loginUser', (newuser,callback)=> {
var body = _.pick(newuser, ['email', 'password']);
console.log('body is:', body);
User.findByCredentials(body.email, body.password).then((user) => {
return user.generateAuthToken().then((token) => {
if (token) {
console.log('token was found');
let rooms = ['Cats', 'Dogs', 'Birds'];
callback(rooms);
} else {
socket.emit('loginFailure', {'msg' : 'Login failure'});
}
}).catch((e) => {
throw e;
});
}).catch((e) => {
socket.emit('loginFailure', {'msg' : 'Login failure'});
throw e;
});
});
我可以在控制台中看到打印出来的'token was found'
,但没有收到在浏览器控制台中打印的房间。我也没有收到任何错误
我想知道这是因为vue.js方法是如何工作的?如果是这样的话,有什么办法吗?您忘了在回调中指定
房间
作为参数
loginUser: function () {
socket.emit('loginUser', {
email: this.email ,
password: this.password
}, function(rooms) { // need to have rooms argument
console.log('rooms in callback are:', rooms);
});
}