当前位置: 首页 > wzjs >正文

高校网站群建设的公司有哪些收录好的网站有哪些

高校网站群建设的公司有哪些,收录好的网站有哪些,营销型网站建设的概念,怎么做视频解析网站吗什么?打包空白?分享一下我的解决方法! 第一步 找大师算过了,装4.1版本运气好! 所以根目录执行命令… npm install mqtt4.1.0第二步 自己封装一个mqtt文件方便后期开坛做法! // utils/mqtt.js import mqt…

什么?打包空白?分享一下我的解决方法!

第一步
找大师算过了,装4.1版本运气好!
所以根目录执行命令…

npm install mqtt@4.1.0

第二步
自己封装一个mqtt文件方便后期开坛做法!

// utils/mqtt.js
import mqtt from 'mqtt/dist/mqtt'class MQTTClient {constructor() {this.client = nullthis.subscriptions = new Map()this.reconnectTimer = nullthis.config = {host: 'mqtt://your-broker.com',options: {clientId: 'uni-app-' + Date.now(),keepalive: 60,clean: true,reconnectPeriod: 5000}}}init() {if (!this.client) {this.connect()}}connect() {this.client = mqtt.connect(this.config.host, this.config.options)this.client.on('connect', () => {console.log('MQTT Connected')this.resubscribe()})this.client.on('message', (topic, message) => {this.handleMessage(topic, message)})this.client.on('error', (err) => {console.error('MQTT Error:', err)})this.client.on('close', () => {console.log('MQTT Connection closed')this.scheduleReconnect()})}subscribe(topic, callback) {if (!this.subscriptions.has(topic)) {this.subscriptions.set(topic, new Set())if (this.client?.connected) {this.client.subscribe(topic)}}this.subscriptions.get(topic).add(callback)}unsubscribe(topic, callback) {if (this.subscriptions.has(topic)) {const callbacks = this.subscriptions.get(topic)callbacks.delete(callback)if (callbacks.size === 0) {this.subscriptions.delete(topic)if (this.client?.connected) {this.client.unsubscribe(topic)}}}}handleMessage(topic, message) {if (this.subscriptions.has(topic)) {const callbacks = this.subscriptions.get(topic)callbacks.forEach(cb => cb(message.toString()))}}resubscribe() {if (this.client?.connected) {const topics = Array.from(this.subscriptions.keys())if (topics.length > 0) {this.client.subscribe(topics)}}}scheduleReconnect() {if (!this.reconnectTimer) {this.reconnectTimer = setTimeout(() => {this.reconnectTimer = nullthis.connect()}, 5000)}}destroy() {if (this.client) {this.client.end()this.client = null}this.subscriptions.clear()clearTimeout(this.reconnectTimer)}
}export const mqttClient = new MQTTClient()

第三步
打开 main.js 文件
思量前后,觉得还是全局挂载吧

import mqtt from '@/mqtt/dist/mqtt.js'
app.config.globalProperties.$mqtt = mqtt;

第四步
打开这个mqtt.js修改源码,注意,不是你自己创建的mqtt.js,是安装的依赖库文件,路径在根目的node_modules/mqtt/dist里面!!!!!
在这里插入图片描述
然后把里面的代码修改,看图,要改2行!!!源码使用的是 wx.connectSocket,修改之后:uni.connectSocket
最后要加上 complete:()=>{}, 别问为什么,一问你就输了!!!!
在这里插入图片描述
第五步
到这里已经可以使用了,不信你打包一下app试下,自定义基座也是没问题的!
下面是我的使用代码!

<template><view>收到的MQTT内容===>{{msg}}</view>
</template><script>export default {name: "wang-mqtt",data() {return {msg: '初始化mqtt'}},created() {// 连接配置let myOptions = {clientId: 'uni-app-' + Date.now(),keepalive: 60,clean: true,reconnectPeriod: 5000}let ip = ''// #ifdef H5ip = 'ws://你的IP:8083/mqtt'// #endif// #ifdef APP-PLUSip = 'wx://你的IP:8083/mqtt'// #endif// 创建 MQTT 客户端const client = this.$mqtt.connect(ip, myOptions);// 订阅主题client.subscribe('app_xxdg/topic', (err) => {if (!err) console.log('成功已订阅主题');});// 监听消息client.on('message', (topic, message) => {this.msg = message.toString()console.log(`收到消息:`, message.toString());});},methods: {}}
</script>
<style>
</style>
http://www.dtcms.com/wzjs/436082.html

相关文章:

  • 创建网站的向导和模板 信息技术教资面试seo推广是什么
  • 幼教网站建设分析做外贸有哪些网站平台
  • 国家重大建设项目网站地址成人零基础学电脑培训班
  • 新版在线天堂网怎么做seo关键词优化
  • 用c 做一个小网站怎么做网站推广100种方法
  • php怎么做全网小视频网站怎么在百度上打广告
  • 网站程序语言网络营销策划方案模板范文
  • 网站平台客服系统河北网站推广
  • 做招聘网站没有数据建站abc网站
  • 做网站的盈利模式网页优化公司
  • 仿站 flash网站线上网络推广怎么做
  • 做影集的网站或软件产品软文范例
  • 买网站做seo网络营销渠道有哪三类
  • 哈尔滨建设工程招投标网郑州网站建设方案优化
  • 找人做logo网站石家庄新闻
  • seo站长博客免费网站模板
  • 兰州新区城乡建设局网站长沙排名推广
  • 在自己的网站上怎么做淘宝客做网站需要多少钱 都包括什么
  • 温州公司建设网站制作专门做网站的公司
  • 公司平台网站建设什么样的人适合做策划
  • 怎样做网站外部链接seo海外推广
  • wordpress 多语言切换搜狗搜索引擎优化
  • 如何设计营销 网站建设站长之家排行榜
  • 设计本官方网站广告我在百度下的订单如何查询
  • 南京建设网站报价上海seo优化服务公司
  • 厦门市建设工程质监站网站怎么建网站教程
  • 沧州商城网站开发设计seo是什么职业
  • 企业营销网站建设公司网络销售推广公司
  • 网站结构与导航设计电脑培训机构哪个好
  • 吴忠市利通区建设局网站推广普通话的意义30字