【发布时间】:2017-05-08 14:25:59
【问题描述】:
当我尝试在套接字回调函数中读取我的道具时,它会抛出一个错误:
componentWillMount(){
console.log(this.props.username); // works
this.props.socket.on('question', function(){
console.log(this.props.username); //prints Cannot read property 'username' of undefined
}
});
}
我该如何解决这个问题?
【问题讨论】: