l***@qq.com
l***@qq.com
  • 发布:2020-09-09 10:46
  • 更新:2021-01-06 18:01
  • 阅读:3942

#插件讨论# 【 mqtt-demo - 猫猫猫猫 】APP端运行demo正常,协议改成mqtt:// 报错WS is not a constructor

分类:uni-app

APP端链接mqtt协议提示WS

var mqtt = require('mqtt/dist/mqtt.js')  
var client = mqtt.connect('mqtt://192.168.1.116:1883')

报错
[Vue warn]: Error in v-on handler: "TypeError: WS is not a constructor"
(found at pages/index/index.vue:1)
TypeError: WS is not a constructor

在'mqtt/dist/mqtt.js'里面打印
var WS = require('ws')
console.log(WS) // WS ===> null

2020-09-09 10:46 负责人:无 分享
已邀请:
喜欢技术的前端

喜欢技术的前端 - QQ---445849201

大神,你这个解决了吧,给我指导一下呗,我看例子中是wx://

小菜啊

小菜啊 - 业精于勤荒于嬉

大佬你好,我也是这个问题,npm 命令是这个: npm install mqtt@3.0.0,方便解答一下么

  • 喜欢技术的前端

    var hosts = '',

    // #ifdef H5

    hosts = 'ws://' + this.serve.host + ':' + this.serve.port + this.serve.path

    //#endif

    // #ifdef MP-WEIXIN

    hosts = 'wxs://' + this.serve.host + this.serve.path

    //#endif

    // #ifdef APP-PLUS

    hosts = 'wx://' + this.serve.host + ':' + this.serve.port + this.serve.path

    //#endif


    不用mqtt://

    2021-01-07 09:16

  • 小菜啊

    回复 喜欢技术的前端: app端为什么不支持 ws:// 开头的协议呢

    2021-01-07 10:47

该问题目前已经被锁定, 无法添加新回复