Article From:https://segmentfault.com/q/1010000011712545
Question:

Figure:
Why is this event monitoring placed in created?
And why use window.events?

Answer 0:

This is supposed to be two brothers components communicating through event bus.

window.eventsThe Vue object is stored.
window.events = new Vue();

$onIt is used to register an event, so it is placed in created, and $emit triggers the event. You can refer to the Vue event mechanism.

Answer 1:

He should have built an empty Vue instance to do eventbus and put this instance on the window object.
eg:

window.events = new Vue();
window.events.$on(...)

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *