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);