是否可以将HubProxy设置为变量并访问其方法? 例如:
conectarChat() {
const connection = signalr.hubConnection(url);
connection.logging = true;
const proxy = connection.createHubProxy('chatHub');
this.proxy_signalr = proxy;
// ... connection start and other stuff
}
componentDidMount() {
this.conectarChat();
this.proxy_signalr.on('msgRecebida', (id_enviou, id_recebeu, mensagem) => {
//some function
});
}
如果.on方法在conectarChat()函数内,它可以很好地工作。
谢谢, 布鲁诺