更新记录
1.0.1(2025-04-21)
- 修复鸿蒙打包错误问题
1.0.0(2025-03-19)
- UxFrame MQTT 插件,支持Android、iOS、Web
平台兼容性
uni-app x
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
√ | √ | 5.0 | 12 | - | - |
UxFrame MQTT SDK 1.0.1
特别说明
如果您已经购买了UxFrame 低代码高性能UI框架, 则无需再次购买本插件,请点击上方进入交流群
联系我免费获取离线版插件!
使用方法
import { UxMqtt, UxMqttOptions, UxMqttConnectOptions, UxMqttSubscribeOptions, UxMqttPublishOptions } from '@/uni_modules/ux-mqtt'
const online = ref(false)
const msgList = ref<string[]>([])
const mqtt = new UxMqtt({
brokerUrl: 'tcp://localhost:1883',
clientId: '1',
connectionTimeout: 1,
} as UxMqttOptions)
function connect() {
mqtt.connect({
statusListener: (status: boolean, err: string) => {
online.value = status
if(err != '') {
uni.showModal({
content: err
})
}
},
messageListener: (topic: string, msg: string) => {
msgList.value.push(topic + ': ' + msg)
}
} as UxMqttConnectOptions)
}
function disconnect() {
mqtt.disconnect()
}
function subscribe() {
mqtt.subscribe({
topic: 'test',
success: () => {
console.log('subscribe success');
},
fail: (err: string) => {
console.log(err);
}
} as UxMqttSubscribeOptions)
}
function publish() {
mqtt.publish({
topic: 'test',
msg: JSON.stringify({
name: 'hh',
value: 1
})
})
}