当前位置:网站首页>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

边栏推荐
猜你喜欢

【Halcon视觉】算子的结构
![[leetcode每日一题2021/8/31]1109. 航班预订统计【中等】差分数组](/img/9d/5ce5d4144a9edc3891147290e360d8.png)
[leetcode每日一题2021/8/31]1109. 航班预订统计【中等】差分数组
![[Halcon vision] image gray change](/img/62/426713becba851f034e6008f28bdb0.png)
[Halcon vision] image gray change
![[leetcode每日一题2021/8/30]528. 按权重随机选择【中等】](/img/13/c6cb176d7065035f60d55ad20ed1bf.png)
[leetcode每日一题2021/8/30]528. 按权重随机选择【中等】
![[Halcon vision] affine transformation](/img/f1/32284c71e78e6eea390fdb6058ba0f.png)
[Halcon vision] affine transformation

【Halcon视觉】图像灰度变化

Okaleido ecological core equity Oka, all in fusion mining mode

PLC overview

QRcode二维码(C语言)遇到的问题
![[Halcon vision] Fourier transform of image](/img/9c/d6ed4ab3e40f706f3b5b8b5cc51db9.png)
[Halcon vision] Fourier transform of image
随机推荐
Function template parameters (where are the function parameters)
同步方法中不使用asyncTask<T> 修饰和await获取异步返回值(同步方法中调用异步方法)
比较器(Comparable与Comparator接口)
Interview questions and answers for the second company (2)
[socket] the three handshakes are completed in listen, and accept only takes out one connection from the queue that completes the connection
【Halcon视觉】极坐标变换
Controller返回JSON数据
PLC概述
The reason why go language is particularly slow to develop run and build commands
SAP ABAP Netweaver 容器化的一些前沿性研究工作分享
面试第一家公司的面试题及答案(一)
2022pta usual training questions (1-10 string processing questions)
STM32 阿里云MQTT esp8266 AT命令
.NET 开源框架在工业生产中的应用
js翻页、kkpager.js翻页
Tradingview tutorial
[Halcon vision] morphological corrosion
Google与Pixar开发Draco支持USD格式 加速3D对象传输&lt;转发&gt;
The problem of incomplete or partial display of the last recyclerview is solved
微信公众号发布提醒(微信公众号模板消息接口)