const client:mqtt.MqttClient=mqtt.connect("wx://124.221.166.114:8803/mqtt",{clientId: 'clientid', username: "user", password: "passw", });
- 发布:2023-03-02 11:59
- 更新:2023-03-28 23:10
- 阅读:456
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 19044.2604
HBuilderX类型: 正式
HBuilderX版本号: 3.6.18
手机系统: Android
手机系统版本号: Android 8.0
手机厂商: 华为
手机机型: evr-an00
页面类型: vue
vue版本: vue3
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
const client:mqtt.MqttClient=mqtt.connect("wx://124.221.166.114:8803/mqtt",{clientId: 'clientid', username: "user", password: "passw", });
const client:mqtt.MqttClient=mqtt.connect("wx://124.221.166.114:8803/mqtt",{clientId: 'clientid', username: "user", password: "passw", });
预期结果:
TypeError: socketTask.onOpen is not a function
TypeError: socketTask.onOpen is not a function
实际结果:
TypeError: socketTask.onOpen is not a function
TypeError: socketTask.onOpen is not a function
bug描述:
个人认为socketTask = wx.connectSocket({
url: url,
protocols: [websocketSubProtocol]
})这个函数无法创建连接,导致TypeError: socketTask.onOpen is not a function出错,因该是这样,H5正常,APP出错
1***@163.com
已解决,在mqtt.js 文件里
socketTask = wx.connectSocket({
url: url,
protocols: websocketSubProtocol,
success(){} //增加这行
})
2023-03-29 01:58
2***@qq.com
回复 1***@163.com: 我也遇到了这个问题,将Vue版本从3降为2也可以解决。请问一下你这个解决方法是怎么想到的呢?
2024-04-23 17:37
2***@qq.com
回复 2***@qq.com: 是因为这个吗?如果希望返回一个 socketTask 对象,需要至少传入 success / fail / complete 参数中的一个。https://uniapp.dcloud.net.cn/api/request/websocket.html#connectsocket
2024-04-23 17:40