[Vuejs]-Is it possible to refer to a global bus in the template of a component?

0👍

You can initialize the bus to a data property like this:

data: {
    eventBus: bus
}

then you can do it in the template like this :

<div v-for="c in aList" v-on:click="eventBus.$emit('casedetails',c._source)">something</div>

but i prefer the first approach you are doing is better

0👍

If you have one global bus for all of your Vue components, you can add it to the prototype of Vue like so:

Vue.prototype.$bus = new Vue();

Then, each Vue instance will have a reference to that bus via this.$bus, which would be directly accessible in any template:

<div v-on:click="$bus.$emit(c._source)">something</div>

Leave a comment