f***@foxmail.com
f***@foxmail.com
  • 发布:2022-06-29 19:13
  • 更新:2022-12-02 11:37
  • 阅读:1317

vue3 + mqtt 3.0,编译成APP,mqtt 连接报错

分类:uni-app

使用官方 vue3模板,引用 mqtt@3.0.0,web 和 微信小程序都正常工作。
唯独app报错,TypeError: socketTask.onOpen is not a function
(app 和 微信小程序,已使用 wxs:// 协议)

vue2下一切正常
怀疑 vite,但不知道怎么排查

代码如下:

import * as mqtt from 'mqtt/dist/mqtt.js'  

      connectToMqtt() {  
        const connectParam = {  
            clientId: ''  
            username: ''  
            password: ''  
            clean: false,  
        }  
        // #ifdef H5  
        this.mqttClient = mqtt.connect('wss://xxxxxxxx', connectParam)  
        // #endif  

        // #ifdef MP-WEIXIN || APP-PLUS  
        console.log('wxs://xxxx');  
        this.mqttClient = mqtt.connect('wxs://xxxxxxxx', connectParam)  
        // #endif  

        this.mqttClient.on('connect', function(connack) {  
            console.log('成功建立起mqtt连接')  
        })  

        this.mqttClient.subscribe('001', err => {  
            if (!err) {  
                console.log('订阅了私聊topic: 001')  
            }  
        })  

        this.mqttClient.on('error', (error) => {  
            console.log('连接失败:', error)  
        })  

        this.mqttClient.on('message', (topic, message) => {  
          this.title = topic + ':  ' + message.toString()   
            console.log('收到消息:', topic, message.toString())  
        })  

        setTimeout(()=> {  
          this.mqttClient.publish("001", "hello world! "+ new Date().getTime())  
        },1500)  
       }
2022-06-29 19:13 负责人:无 分享
已邀请:
booooom

booooom - booooooom

你好 vue3 mqtt 这个问题解决了吗

浅水321

浅水321

请教下,这个错误怎么处理的,切换到V2吗

要回复问题请先登录注册