vue中 evenBus调用,兄弟间传值

main.js中----------
new
Vue({ router, store, data: { eventHub: new Vue() }, render: h => h(App), watch: { '$route.path': function(newVal, oldVal) { const userId = this.$route.query.userId || localStorage.getItem('userIds'); const parkId = this.$route.query.id || localStorage.getItem('parkId'); this.$router.push({ query: { id: parkId, userId: userId } }); localStorage.setItem('userIds', userId); localStorage.setItem('parkId', parkId); } } }).$mount("#app");
this.$root.eventHub.$on("controlbgChange", (res) => {
       console.log('res',res)
      });
this.$root.eventHub.$emit("controlbgChange", path);
原文地址:https://www.cnblogs.com/Byme/p/14662589.html