2👍
You just defined the EventBus
in the app.js file.
It is not accessible in the TransactionList.vue component as it has no reference to the EventBus
So export the EventBus
in your app.js as
export const EventBus = new Vue();
And then import the EventBus
in your components script as
<script>
import {EventBus} from './path/to/app.js'
export default {
}
</script>
1👍
Create the event bus in it’s own file:
// bus.js
import Vue from 'vue'
const bus = new Vue()
export default bus
The import it into the components you want to use it in:
import bus from 'bus'
export default {
...
methods: {
myMethod () {
bus.$emit('my-event', 'test')
}
}
...
}
Source:stackexchange.com