当前位置:网站首页>Uniapp uses the simple method signalr (only for web debugging, cannot package apps)
Uniapp uses the simple method signalr (only for web debugging, cannot package apps)
2022-07-26 10:33:00 【Miners learn programming】
ASP.NET Core SignalR It's an open source library , Simplify real-time web Features added to the application . real time web The function enables the server-side code to push the content to the client immediately .
Apply to SignalR :
- Applications that require frequent updates from the server . Examples include games 、 Social networks 、 vote 、 The auction 、 Maps and GPS application .
- Dashboards and monitoring applications . Examples include corporate dashboards 、 Instant sales updates or travel alerts .
- Collaborative applications . Examples of collaborative applications include whiteboard applications and team meeting software .
- Applications that require notification . Social networks 、 E-mail 、 Chat 、 game 、 Travel alerts and many other applications require notifications .
SignalR Provide a API, Used to create (RPC) Server to client Remote procedure call . Rpc Through the server side .NET Core The code is called from the client JavaScript function .
uniapp How to connect correctly signalR Well ? Referring to many materials above, we use websocket, Maybe my skills are not good , Use according to the example blog uniapp Of websocketAPI Can only be connected signalR, Unable to get and send messages normally . So what should we do ?
By looking carefully signalr JavaScript client Code for ,signalr No longer dependent on jQuery, As long as you can get it right signalR example , You can communicate normally . After a simple attempt , Finally, the test succeeded . The specific steps are as follows .
1、 Follow the official Microsoft tutorial , obtain signalR JavaScript The code base signalr.js、signalr.js.map、signalr.min.js and signalr.min.js.map These four documents . The official tutorial .

2、 Copy the obtained file to uniapp In the project .
I put it in j/s/ Under the table of contents

3、 introduce signalr, And in onLoad Read data from . The code can refer to JavaScript client Code to write . As long as you get it smoothly signalr example , You can communicate normally . Here I directly copy the official code , Have to say , Microsoft's improvements are amazing .
<script>
let signalR = require('../../js/signalr.js')
export default {
onLoad() {
const connection = new signalR.HubConnectionBuilder()
.withUrl("http://localhost:56630/chathub")
.configureLogging(signalR.LogLevel.Information)
.build();
async function start() {
try {
await connection.start();
console.log("SignalR Connected.");
} catch (err) {
console.log(err);
setTimeout(start, 5000);
}
};
connection.onclose(start);
start();
// Receive data and pop up
connection.on("ReceiveMessage", function (user, message) {
console.log(message);
});
},
data() {
return {
}
},
methods: {
}
}
</script>4、 effect

边栏推荐
- Interview questions and answers of the first company (I)
- 码云,正式支持 Pages 功能,可以部署静态页面
- Using native JS to realize custom scroll bar (click to reach, drag to reach)
- About the declaration and definition of template functions [easy to understand]
- 分布式锁解决方案之Redis实现
- 函数模板参数(函数参数在哪)
- The software cannot be opened
- 2022pta平时训练题(1~10题字符串处理问题)
- .NET操作Redis List列表
- algorithm
猜你喜欢

Unit test, what is unit test and why is it so difficult to write a single test

Navicat15连接本地虚拟机的Mysql(Centos7)

SAP ABAP Netweaver 容器化的一些前沿性研究工作分享

我们的Web3创业项目,黄了

Li Kou daily question 917

码云,正式支持 Pages 功能,可以部署静态页面
![[Halcon vision] software programming ideas](/img/9b/a27338689ee4598dac88f6e5d92053.png)
[Halcon vision] software programming ideas
![[Halcon vision] image filtering](/img/7a/b95f8977f02fab644ef9fb205424e7.png)
[Halcon vision] image filtering
![[Halcon vision] image gray change](/img/62/426713becba851f034e6008f28bdb0.png)
[Halcon vision] image gray change

【Halcon视觉】形态学腐蚀
随机推荐
移动端H5开发常用技巧总结
一些你不知道的 web API
Review of database -- 3. SQL language
【Halcon视觉】数组
Listening freely, the next stop of online text traffic competition?
2022/07/25------字符串的排列
Okaleido ecological core equity Oka, all in fusion mining mode
Inheritance method of simplified constructor (I) - combined inheritance
.NET操作Redis sorted set有序集合
畅听,网文流量竞争的下一站?
Cause: could't make a guess for solution
[Halcon vision] Fourier transform of image
数据分析入门 | kaggle泰坦尼克任务(一)—>数据加载和初步观察
码云,正式支持 Pages 功能,可以部署静态页面
[C language] LINQ overview
Mlx90640 infrared thermal imager temperature sensor module development notes (6)
The difference between equals and = =
js翻页、kkpager.js翻页
【Halcon视觉】算子的结构
结构体操作报错:Segmentation fault (core dumped)