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>
- [Vuejs]-How to get data from a nested component
- [Vuejs]-Google Sign in with client.js in Vue, authentication never saved to session storage
Source:stackexchange.com