565220921@qq.com
565220921@qq.com
  • 发布:2017-07-06 11:11
  • 更新:2019-05-28 10:27
  • 阅读:878

急问hbuilder支持SignalR吗

分类:5+ SDK

如题,hbuilder做的客户端有个聊天功能,能支持SignalR吗,我web网页测试没有问题,放到hbuilder里面不行呢。求解!

2017-07-06 11:11 分享
已邀请:
23569787@qq.com

23569787@qq.com - 80后

同问...

xm3530@126.com

xm3530@126.com - 白白的小白

同问

zhongpei

zhongpei - 1984

支持。

390168930@qq.com
冷魂浪子

冷魂浪子

似乎用不了,signalr需要jquery,uni用不了jquery,找了个不需要jq的版本能连接上和接收消息,但是发送消息有问题.可以尝试下.net core版的signalr,好像这个版本的可以不用jq

beetle2013

beetle2013

微软有个例子,它用原生JS写的,运行在Chrome中是正常工作的。
我在UNI中,改写了一下代码,在Chrome中调试,可以发消息,但是接收消息的方法没有触发。代码如下:

<template>  
    <view class="content">  
        <view>  
            <input type="text" v-model="user">  
            <input type="text" v-model="message">  
            <button @click="sendMsg">send</button>  
        </view>  
        <view>  
            <text v-for="message in messages" :key="message"></text>  
        </view>  
    </view>  
</template>  

<script>  
    import * as signalR from "@aspnet/signalr";  
    import { Toast } from "../../utils/index"  
    export default {  
        data() {  
            return {  
                connection: null,  
                messages: [],  
                user: '',  
                message: ''  
            }  
        },  
        onLoad() {  
          this.connection = new signalR.HubConnectionBuilder()  
            .withUrl("http://localhost:61625/chatHub")  
            .build();  
        },  
        onReady () {  
            this.connection.start({ transport: ['webSockets'] }).catch(err => {  
                Toast(err);  
            })  

            this.connection.on("messageReceived", (user, message) => {  
                console.log('messageReceived')  
                var msg = message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");  
                var encodedMsg = user + " says " + msg;  
                this.messages.push(encodedMsg)  
            });  
        },  
        methods: {  
            sendMsg () {  
                this.connection.invoke("SendMessage", this.user, this.message).catch(function (err) {  
                    return console.error(err.toString());  
                });  
            }  

        }  
    }  
</script>  

真机运行报错,无法运行,错误如下:

10:17:11.983 17:12.318 11603 11624 E console : [ERROR] reportJSException >>>> exception function:createInstance, exception:Exception: Error: module "common/request" is not defined  
10:17:12.013 17:12.318 11603 11624 E console : require@(global function):8:663258  
10:17:12.033 17:12.318 11603 11624 E console : (global function):8:663006  
10:17:12.063 17:12.318 11603 11624 E console : (global function):13104:30  
10:17:12.093 17:12.318 11603 11624 E console : E:\Projects\kingsland\app\node_modules\@aspnet\signalr\dist\esm\NodeHttpClient.js@(global function):13170:34  
10:17:12.113 17:12.318 11603 11624 E console : __webpack_require__@(global function):1299:35  
10:17:12.153 17:12.318 11603 11624 E console : E:\Projects\kingsland\app\node_modules\@aspnet\signalr\dist\esm\DefaultHttpClient.js@(global function):10683:42  
10:17:12.183 17:12.318 11603 11624 E console : __webpack_require__@(global function):1299:35  
10:17:12.213 17:12.318 11603 11624 E console : E:\Projects\kingsland\app\node_modules\@aspnet\signalr\dist\esm\index.js@(global function):13913:45  
10:17:12.243 17:12.318 11603 11624 E console : __webpack_require__@(global function):1299:35  

求指教。

要回复问题请先登录注册