vue-mqtt

Connect to mqtt through websocket, implementation for Vuejs 2
7,696 95
Install
npm install vue-mqtt
Latest Version:2.0.3
License:MIT
Last Updated:Oct 1, 2021
Links: GitHub  ·  npm
Maintainer: nik-zp

Vue-Mqtt

Connect to mqtt through websocket, implementation for Vuejs 2

Example

Example Vue-Mqtt-Example

Install

npm install vue-mqtt --save

Usage

Configuration
import VueMqtt from 'vue-mqtt';
Vue.use(VueMqtt, 'ws://iot.eclipse.org/ws', options);

options: https://github.com/mqttjs/MQTT.js#client

Subscribe
this.$mqtt.subscribe('param/param/param/test', options)

options: https://github.com/mqttjs/MQTT.js#subscribe

On Vuejs instance usage

The last parameter for reading is used

var vm = new Vue({
  mqtt: {
    'param/+/+/test': function(val) {
      console.log('param/+/+/test')
    },
    'param/#': function(val) {
      console.log('param/#')
    },
    'param/param/param/test': function(val) {
      console.log('param/param/param/test')
    },
    'template/+' (data, topic) {
      if (topic.split('/').pop() === '12345') {
        console.log('topic:', 'template/12345')
      }
    },
    'template/+/param/param' (data, topic) {
      if (topic.split('/')[1] === '12345') {
        console.log('topic:', 'template/12345/param/param')
      }
    }
  },
  methods: {
    clickSub: function(val) {
        this.$mqtt.subscribe('param/param/param/test')
    },
    clickPub: function(val) {
        this.$mqtt.publish('param/param/param/test', 'message')
    }
  }
})

Related Packages

vue-simple-websocket

A simple native reconnecting websocket for Vue.js

1,595 9
vue-json-rpc-websocket

JSON-RPC Websocket client for VueJS with Vuex integration

677 12
vue-native-websocket

Native WebSocket plugin and composable for Vue 3

478,654 935
vue-native-websocket-vue3

支持vue3和vuex、pinia的websocket插件

162,849 221
@hlf01/vue3-socket.io

Socket.io implementation for Vue.js 3.0

13,353 2

Version History

Version Released License
2.0.3 MIT
2.0.2 MIT
2.0.1 MIT
2.0.0 MIT
1.0.2 MIT