Search code examples
vue.jsvue-resourcevue-componentvue-router

How to handle $dispatch and $broadcast deprecations in Vue.js?


I was working on a large-scale Vue.js application, and I have used broadcast and dispatch tons of places in my application. What's the best way to sit down and change all these? Or do I have some other way to deal with these breaking-changes?


Solution

  • Both these methods now are merged in the $emit method.

    Unfortunately, replacing every instance of $broadcast and $dispatch with $emit will not work because the pattern used to manage events the one of the 'event emitter' now.

    In my opinion the quickest way to deal with this deprecation is to create a spurious Vue instance and use it as an event hub.