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

更新时间:2023-07-01 11:34:40 阅读: 评论: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",
"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",
"xlsx":"^0.16.0",
"ztree":"3.5.24",
"pubsub-js":"^1.9.0"
},
下载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}});
vue页⾯订阅消息的⽤法:
//订阅⼀个消息
mounted(){
pubSub.subscribe("current_xzq", (msg, current_xzq)=>{伊五行属什么
this.init_xzqdm(current_xzq);
alert(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-01 11:34:40,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1063063.html

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

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