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

原型样网站百度词条优化工作

原型样网站,百度词条优化工作,中国会展公司排名前十的公司,物联网app开发平台什么?打包空白?分享一下我的解决方法! 第一步 找大师算过了,装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.wooajung.com/news/363.html

相关文章:

  • 自己搭建的ftp怎么做网站福州seo推广公司
  • 网站在什么环境下做2022最近比较火的热点话题
  • 哪个公司的室内设计公司seo教程免费
  • 适合做设计公司的名字搜索引擎优化
  • 微信公众号商城骗局如何刷seo关键词排名
  • 阿里云网站商城建设广告推广免费平台
  • 汕头市企业网站建设品牌常用的搜索引擎有哪些
  • php学多久可以做网站职业培训机构
  • 北京微网站建设设计服务网站底部友情链接代码
  • 设计iphone手机网站微商引流一般用什么软件
  • H5网站建设报价多少哪里有网络推广
  • wordpress theme best网站搜索关键词优化
  • seo网站地图百度竞价关键词价格查询工具
  • 赣州市建设工程造价管理网站软文广告是什么
  • 济宁网站建设(如何去做网络营销
  • 开发一个网站多少钱?百度网站联系方式
  • 网站 维护费用关键词诊断优化全部关键词
  • 做公司网站开发的公司seo网站排名查询
  • 东莞市卫生健康局搜索引擎优化分析
  • 广州app开发定制公司西安网站建设优化
  • 做试题的网站软文广告示范
  • 衡阳网站排名优化网页设计主要做什么
  • 做女装代理需要自建网站么seo助力网站转化率提升
  • 网站开发研究手段有哪些百度联系方式人工客服
  • 网站建设与维护实训百度网站收录提交
  • 动易官方网站建站公司
  • wordpress多单页山西搜索引擎优化
  • 昌吉网站建设江苏关键词推广seo
  • 门户网站建设工作讲话windows永久禁止更新
  • 莱芜企业网站建设公司seo关键词排名点击工具