TypeError: this.$eventBus is not a function at Proxy.mounted

391 Views Asked by At

I am doing migration from vue2 to vue3 and because event emitter($on) moved from vue3, I am getting this error. To avoid this I installed tiny-emitter (https://www.npmjs.com/package/tiny-emitter) but error didnt change after I applied it. Here is the version of my application when it was in vue2:

mounted() {
  this.$eventBus().$on('open-dropdown', () => {
    this.isDropOpen = !this.isDropOpen;
  });
}

And here is vue3 version:

import emitter from 'tiny-emitter/instance';

export default {
$on: (...args) => emitter.on(...args),
  $once: (...args) => emitter.once(...args),
  $off: (...args) => emitter.off(...args),
  $emit: (...args) => emitter.emit(...args),
mounted() {
    this.$eventBus().$emit('open-dropdown', () => {
      this.isDropOpen = !this.isDropOpen;
    });
  },
}

even I added tiny-emitter, like I said I am getting the same error. So what do I do wrong?

0

There are 0 best solutions below