vuejs未捕获类型错误:非法调用mqtt

vh0rcniy  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(299)

我有一个electron vuejs应用程序,必须在其中发送/接收mqtt消息。
我正在使用VUE3.0.0和mqtt 4.2.8
已建立到代理的连接,但每次我要发布消息时,它都会抛出一个错误
我得到的错误

Uncaught TypeError: Illegal invocation            internal/stream_base_commons.js:134
    at writevGeneric (internal/stream_base_commons.js:134)
    at Proxy.Socket._writeGeneric (net.js:783)
    at Proxy.Socket._writev (net.js:792)
    at doWrite (internal/streams/writable.js:375)
    at clearBuffer (internal/streams/writable.js:521)
    at Proxy.Writable.uncork (internal/streams/writable.js:317)
    at uncork (writeToStream.js?7135:80)
    at processTicksAndRejections (internal/process/task_queues.js:79)

my app.vue(缩写)

<script>
import timer from "./components/Timer"
import { remote } from "electron"
import mqtt from "mqtt"

export default {
  name: 'App',
  components: {
    timer
  },
  data() {
    return {
      mqttClient: null,
    }
  },
  beforeMount(){
    this.mqttClient = mqtt.connect(configManager.getConfig().brokerUrl, { 
      clean: true
    })

    this.mqttClient.on("connect", this.onMqttConnect)
    this.mqttClient.on("error", this.onMqttError)
  },
  methods: {
    onMqttConnect(){
      console.log("Mqtt Connected!") // This works
      this.mqttClient.publish("Test", "Test") // Here is the error
    },
    onMqttError(err){
      alert(err)
    }
  }
}
</script>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题