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—