I have a Vue component with Navigation and layout that uses a bus to communicate with sub components. The bus is passed as a prop to sub components which then use $emit.
export default class Dashboard extends Vue {
protected bus: Vue = new Vue();
mounted() {
if (this.bus != null) {
this.bus.$on("save", () => {
//
});
}
}
}
@Component({ props: ["bus"] })
export default class Child extends Vue {
protected bus!: Vue;
save() {
this.bus.$emit("save");
}
}
This works fine in the standard case.
In the case of Vue Router how can I inject the bus component from the parent into the children?
this.$emit(`${this.$route.params.prefix}:save`)
. – Alex Brohshtut