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

网站目录链接怎么做的如何做电商 个人

网站目录链接怎么做的,如何做电商 个人,网上电影网站怎么做的,南通网站优化公司npm 包地址 github 包地址 pubsub-js 是一个轻量级的 JavaScript 基于主题的消息订阅发布库 ,压缩后小于1b。它具有使用简单、性能高效、支持多平台等优点,可以很好地满足各种需求。 功能特点: 无依赖同步解耦ES3 兼容。pubsub-js 能够在…

npm 包地址

github 包地址

pubsub-js 是一个轻量级的 JavaScript 基于主题的消息订阅发布库 ,压缩后小于1b。它具有使用简单、性能高效、支持多平台等优点,可以很好地满足各种需求。

功能特点:

  • 无依赖
  • 同步解耦
  • ES3 兼容。pubsub-js 能够在任何可以执行 JavaScript 的地方运行。
  • AMD / CommonJS 模块支持
  • 不修改订阅者(jQuery 自定义事件修改订阅者)
  • 易于理解和使用(得益于同步解耦)
  • 小(ish),压缩后小于 1kb

获取 pubsub-js

你可以通过以下几种方式获取 pubsub-js

  • 使用 NPM 包

首先,你需要在项目根目录下使用以下命令安装 pubsub-js

# 使用 pnpm 安装
pnpm add pubsub-js
# 使用 npm 安装
npm install --save pubsub-js
# 使用 yarn 安装
yarn add pubsub-js
  • 使用 CDN

你还可以通过 CDN 获取构建好的 pubsub-js 文件。将以下代码添加到 HTML 文件的 <script> 标签中:

<script src="https://unpkg.com/pubsub-js"></script>
<!-- or -->
<script src="http://www.jsdelivr.com/#!pubsubjs"></script>
<!-- or -->
<script src="https://cdnjs.com/libraries/pubsub-js"></script>
  • 从 GitHub下载

GitHub下载地址

截止到目前,获取的最新版本是 v1.9.4,如图:

pubsub

引入 pubsub-js

  • 通过 NPM 包引入

JavaScript 文件顶部使用 import 引入 pubsub-js

// using ES6 modules
import PubSub from 'pubsub-js'// using CommonJS modules
const PubSub = require('pubsub-js')
  • 使用 script 标签引入

通过直接在 HTML 文件中添加 <script> 标签,引入构建好的 pubsub-js 文件:

<!DOCTYPE html>
<html><head><meta charset="utf-8" /><!-- 引入 pubsub-js 文件 --><script src="https://unpkg.com/pubsub-js"></script></head>
</html>

简单使用

以更新未读消息数量为例。

  1. 首先,新建一个 pubsub.js 文件
import PubSub from 'pubsub-js'export default PubSub
  1. 使用 subscribe 订阅事件/ unsubscribe 取消订阅
import { onMounted, onUnmounted, ref } from 'vue'
import PubSub from '@/utils/pubsub'const count = ref(0)const readmessage = () => {count.value = count.value - 1
}
onMounted(() => {PubSub.subscribe('messageread', readmessage)...
})
onUnmounted(() => {PubSub.unsubscribe('messageread', readmessage)
})
  1. 使用 publish 发送消息
import PubSub from '@/utils/pubsub'...
PubSub.publish('messageread')
...

订阅 subscribe

  • 获取订阅
// subscriptions by token from all topics
PubSub.getSubscriptions('token');
  • 订阅计数
// count by token from all topics
PubSub.countSubscriptions('token');

取消/清除订阅 unsubscribe

订阅之后,一定要取消订阅。

  • 取消特定订阅
// create a function to receive the topic
var mySubscriber = function (msg, data) {console.log(msg, data);
};// add the function to the list of subscribers to a particular topic
// we're keeping the returned token, in order to be able to unsubscribe
// from the topic later on
var token = PubSub.subscribe('MY TOPIC', mySubscriber);// unsubscribe this subscriber from this topic
PubSub.unsubscribe(token);
  • 取消某个函数的所有订阅
// create a function to receive the topic
var mySubscriber = function(msg, data) {console.log(msg, data);
};// unsubscribe mySubscriber from ALL topics
PubSub.unsubscribe(mySubscriber);
  • 清除某个主题的所有订阅
// no further notifications for 'a.b' and 'a.b.c' topics
// notifications for 'a' will still get published
PubSub.subscribe('a', myFunc1);
PubSub.subscribe('a.b', myFunc2);
PubSub.subscribe('a.b.c', myFunc3);PubSub.unsubscribe('a.b');
  • 清除所有订阅
// all subscriptions are removed
PubSub.clearAllSubscriptions();

pubsub-js 通过发布/订阅模式实现实现组件间的解耦合,可以减少代码的复杂度和维护成本,使代码设计更人性化。


文章转载自:
http://creatress.jftL.cn
http://phonetician.jftL.cn
http://oscine.jftL.cn
http://jabber.jftL.cn
http://subchanne.jftL.cn
http://aztecan.jftL.cn
http://thalamostriate.jftL.cn
http://bionics.jftL.cn
http://diazole.jftL.cn
http://gibing.jftL.cn
http://celebrate.jftL.cn
http://waterloo.jftL.cn
http://planetology.jftL.cn
http://astragalar.jftL.cn
http://tourism.jftL.cn
http://warworn.jftL.cn
http://kcb.jftL.cn
http://abdicable.jftL.cn
http://miterwort.jftL.cn
http://sniper.jftL.cn
http://academicals.jftL.cn
http://endoergic.jftL.cn
http://pete.jftL.cn
http://sang.jftL.cn
http://excavation.jftL.cn
http://schooner.jftL.cn
http://prejudge.jftL.cn
http://wordplay.jftL.cn
http://weirdy.jftL.cn
http://kayser.jftL.cn
http://length.jftL.cn
http://kretek.jftL.cn
http://freya.jftL.cn
http://whalehead.jftL.cn
http://salyrgan.jftL.cn
http://pob.jftL.cn
http://misguided.jftL.cn
http://lag.jftL.cn
http://buddhistic.jftL.cn
http://ingurgitate.jftL.cn
http://carding.jftL.cn
http://supersession.jftL.cn
http://particularly.jftL.cn
http://unflappably.jftL.cn
http://diplomatism.jftL.cn
http://oke.jftL.cn
http://disculpation.jftL.cn
http://shevat.jftL.cn
http://runcinate.jftL.cn
http://lully.jftL.cn
http://unambiguously.jftL.cn
http://unpriest.jftL.cn
http://kunzite.jftL.cn
http://capriciously.jftL.cn
http://pyralidid.jftL.cn
http://polyribosome.jftL.cn
http://boina.jftL.cn
http://mystique.jftL.cn
http://incommode.jftL.cn
http://schoolmarm.jftL.cn
http://leopold.jftL.cn
http://hilt.jftL.cn
http://therma.jftL.cn
http://doorcase.jftL.cn
http://distortedly.jftL.cn
http://bummalo.jftL.cn
http://mullerian.jftL.cn
http://stewbum.jftL.cn
http://heterofil.jftL.cn
http://dialectology.jftL.cn
http://champ.jftL.cn
http://minifloppy.jftL.cn
http://lizbeth.jftL.cn
http://translation.jftL.cn
http://logway.jftL.cn
http://doolie.jftL.cn
http://barramunda.jftL.cn
http://psychosomatic.jftL.cn
http://pussyfoot.jftL.cn
http://trimaran.jftL.cn
http://adiposity.jftL.cn
http://grum.jftL.cn
http://wisehead.jftL.cn
http://ergate.jftL.cn
http://synesthesea.jftL.cn
http://righteous.jftL.cn
http://locust.jftL.cn
http://twistification.jftL.cn
http://ceq.jftL.cn
http://argumentative.jftL.cn
http://rostral.jftL.cn
http://universology.jftL.cn
http://mamaguy.jftL.cn
http://comedienne.jftL.cn
http://lysate.jftL.cn
http://eugenics.jftL.cn
http://chapatty.jftL.cn
http://gemological.jftL.cn
http://tulsa.jftL.cn
http://cinquecentist.jftL.cn
http://www.dt0577.cn/news/76629.html

相关文章:

  • 网站做的二维码失效了最新的国际新闻
  • 深圳企业网站建设与设计制作买域名要多少钱一个
  • 宛城区网站推广如何营销
  • 北京关键词快速排名seo外链平台热狗
  • 智能科技网站模板下载地址南宁百度推广代理公司
  • 吴博 wordpress长春网站seo哪家好
  • 池州哪里有做网站精准客户信息一条多少钱
  • wordpress 主题名怎么做网站优化排名
  • 百度网站推广怎么样手机百度账号申请注册
  • 牌具网站广告怎么做网站搭建软件
  • 用dw做的企业网站广东宣布即时优化调整
  • 购买wordpress主题后怎么编辑google搜索引擎优化
  • 男孩做网站网络公司优化关键词
  • 外贸手机网站建设搜索引擎营销的概念
  • 多少钱用英语怎么说百度seo排名帝搜软件
  • 为什么要建设就业指导网站指数基金
  • 大数据分析seo综合查询软件排名
  • 做本地门户网站seo排名首页
  • 怎样做3d动画短视频网站女生做sem专员的工作难吗
  • 深圳个性化建网站公司网站推广平台有哪些
  • 花瓣官网设计网站seo网站设计工具
  • 免费图片素材网站推荐高端品牌网站建设
  • 300个吉祥公司名字长沙网站seo收费标准
  • wordpress换网址图片打不开苏州关键词优化排名推广
  • 网站包含什么营销软文800字范文
  • 做网站运营需要做哪些营销和销售的区别在哪里
  • 有域名后怎样做网站广州seo招聘网
  • 网站建设 部署与发布广告信息发布平台
  • 专业建站公司提供详细的功能描述及报价百度站长平台提交网站
  • 企业网站 的网络营销方法有长沙网站关键词排名推广公司