vue中组件间通信机制之pubsub组件用法

更新时间:2023-07-25 04:18:49 阅读: 评论:0

vue中组件间通信机制之pubsub组件⽤法vue中组件间通信机制之pubsub组件⽤法
在package.json⽂件中导⼊组件依赖:
“pubsub-js”: “^1.9.0”
"dependencies":{
"@jiaminghi/data-view":"^2.9.6",
"cesium":"^1.70.0",
"echarts":"^4.8.0",
"element-ui":"^2.13.1",
"file-saver":"^2.0.2",
"jquery":"^3.3.1",
"ol":"^6.3.1",
"ol-ext":"^3.1.12",
fiercely
"popper.js":"^1.16.1",
"axios":"^0.19.2",
"vue":"^2.5.2",
英文书写体"vue-cesium":"^2.1.4",
"vue-layer":"^1.2.0",
"vue-router":"^3.0.1",
"vue-runtime-helpers":"^1.1.2",
"vuex":"^3.2.0",
"webpack-dev-rver":"^2.11.5",
marketingstrategy
"xlsx":"^0.16.0",
买咖啡
"ztree":"3.5.24",
"pubsub-js":"^1.9.0"normalize
},
下载pubsub-js组件
npm install
#或
cnpm i
vue页⾯中发布消息⽤法:
//发布单个消息
import pubSub from "pubsub-js";
pubSub.publish("current_xzq", that._current_xzqdm);
/
对话玩具/发布多个消息(可在不同的vue页⾯分别执⾏单个的发布操作)
//map.vue中执⾏
pubSub.publish("qdm", {current:{xzqdm:that._current_xzqdm}});
//nd.vue中执⾏
pubSub.publish("current.nd", {current:{nd:that._nd}});mouth什么意思
vue页⾯订阅消息的⽤法:
//订阅⼀个消息
mounted(){
christmas song
pubSub.subscribe("current_xzq", (msg, current_xzq)=>{
this.init_xzqdm(current_xzq);
the strokesalert(current_xzq);
});
},
//订阅多个消息
mounted(){
//绑定订阅
pubSub.subscribe("current", (msg, current)=>{    this.init_qdm,current.nd);
qdm+"-"+current.nd);
});
//绑定resize事件
雅思学校首选北京新航道let that = this;
window.addEventListener(
"resize",
()=>{
},
fal
);
},
—the—end—

本文发布于:2023-07-25 04:18:49,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/187974.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:组件   消息   发布   订阅   间通信   机制
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图