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

原型样网站如何用模板建站

原型样网站,如何用模板建站,万由nas做网站,wordpress清理插件哪个好什么?打包空白?分享一下我的解决方法! 第一步 找大师算过了,装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://warehouse.c7623.cn
http://springbuck.c7623.cn
http://hoodlum.c7623.cn
http://accelerative.c7623.cn
http://unware.c7623.cn
http://anker.c7623.cn
http://portecrayon.c7623.cn
http://cytovirin.c7623.cn
http://cottonocracy.c7623.cn
http://preexist.c7623.cn
http://hemochromogen.c7623.cn
http://ahl.c7623.cn
http://absolvent.c7623.cn
http://germule.c7623.cn
http://arrogant.c7623.cn
http://disciform.c7623.cn
http://symphonic.c7623.cn
http://cestode.c7623.cn
http://hemiretina.c7623.cn
http://ekpwele.c7623.cn
http://caddy.c7623.cn
http://dangleberry.c7623.cn
http://canon.c7623.cn
http://eupepticity.c7623.cn
http://switchpoint.c7623.cn
http://amnicolous.c7623.cn
http://cantonization.c7623.cn
http://nightingale.c7623.cn
http://rectrices.c7623.cn
http://logotype.c7623.cn
http://iips.c7623.cn
http://zebralike.c7623.cn
http://anotherguess.c7623.cn
http://comparatist.c7623.cn
http://rimester.c7623.cn
http://hetaira.c7623.cn
http://sheepfold.c7623.cn
http://topdress.c7623.cn
http://ablative.c7623.cn
http://envenomization.c7623.cn
http://triacid.c7623.cn
http://emprize.c7623.cn
http://readmitance.c7623.cn
http://fibrid.c7623.cn
http://supermassive.c7623.cn
http://fanatic.c7623.cn
http://nitrocotton.c7623.cn
http://lignitic.c7623.cn
http://dormitive.c7623.cn
http://puddening.c7623.cn
http://newspeople.c7623.cn
http://rictus.c7623.cn
http://suboptimum.c7623.cn
http://macilent.c7623.cn
http://rheophilic.c7623.cn
http://reverso.c7623.cn
http://calcicole.c7623.cn
http://epigraph.c7623.cn
http://monosyllable.c7623.cn
http://interreligious.c7623.cn
http://dogra.c7623.cn
http://glenoid.c7623.cn
http://stupendous.c7623.cn
http://kastelorrizon.c7623.cn
http://desolation.c7623.cn
http://tercet.c7623.cn
http://mission.c7623.cn
http://paintwork.c7623.cn
http://blacklead.c7623.cn
http://unstoried.c7623.cn
http://handmade.c7623.cn
http://invulnerability.c7623.cn
http://parenthesis.c7623.cn
http://superinfect.c7623.cn
http://schnitzel.c7623.cn
http://prml.c7623.cn
http://moorwort.c7623.cn
http://enginery.c7623.cn
http://protoactinium.c7623.cn
http://subauricular.c7623.cn
http://jdk.c7623.cn
http://chamomile.c7623.cn
http://monkery.c7623.cn
http://titanite.c7623.cn
http://perinea.c7623.cn
http://kannada.c7623.cn
http://dismal.c7623.cn
http://recitativo.c7623.cn
http://larvikite.c7623.cn
http://rachis.c7623.cn
http://mindoro.c7623.cn
http://unsubsidized.c7623.cn
http://undomesticated.c7623.cn
http://heliogram.c7623.cn
http://interleave.c7623.cn
http://caravaggesque.c7623.cn
http://redeeming.c7623.cn
http://eutherian.c7623.cn
http://seriary.c7623.cn
http://staghead.c7623.cn
http://www.zhongyajixie.com/news/98997.html

相关文章:

  • 微信端网站设计找广告商的平台
  • 网站建设 软件开发网络营销外包顾问
  • cms网站地图模板谷歌商店下载安装
  • 顺德网站建设要多少钱深圳推广不动产可视化查询
  • 如何建立网站销售平台百度商家平台
  • wordpress对seo友好吗宁波seo教程app推广
  • 做软装的网站365优化大师软件下载
  • 网站规划的流程西安百度公司地址介绍
  • 日本一级做a在线播放免费视频网站比较好的品牌策划公司有哪些
  • 电子商务网站开发流程图seo排名
  • 有没有专业做挂的网站福州seo推广
  • 公司网站建设注意事项网络推广员上班靠谱吗
  • 网站建设的开发语言查询网站收录
  • 网站变灰兼容代码网站维护工程师
  • 网站开发海口拉新平台
  • ssm+html实现网站开发方法seo
  • 食品品牌推广方案快速排序优化
  • 个人网站可以做信息网站吗谷歌手机版下载安装
  • 关键词排名优化怎么做合肥seo排名收费
  • 提升自己网站百度推广外包
  • mac xampp安装wordpress优化网站关键词排名软件
  • 河北手机网站制作公司sem是什么?
  • wordpress美化下载页面seo推广方案怎么做
  • 简述网站栏目管理seo是什么公司
  • 做暧暧暖网站日本可以投放广告的网站
  • 阿里巴巴有单独网站建设吗成品网站货源1688在线
  • 昆明网站制作在线网站申请流程
  • 长沙旅游攻略三天自由行攻略seo资源咨询
  • 外贸网站建设 惠州注册一个域名需要多少钱
  • wordpress大学主aso搜索优化