1. 版本(与后端统一版本)
npm install @aspnet/signalR(不依赖于jquery)2. 常见报错
2.1跨域问题
2.2沟通好 传值于接收的方法名
const connection = new signalR.HubConnectionBuilder() .withUrl("/chatHub") .configureLogging(signalR.LogLevel.Information) .build(); connection.start().catch(function (err) { return console.error(err.toString()); connection.invoke("SendMessage", user, message).catch(err => console.error(err.toString())); connection.on("ReceiveMessage", (user, message) => { const encodedMsg = user + " says " + message; const li = document.createElement("li"); li.textContent = encodedMsg; document.getElementById("messagesList").appendChild(li); }); })