'this.$emit throws TypeError

I'm creating a small vue3 component and need to emit an event on a method call.

This is roughly how it looks :

export default {
  emits: ['event'],
  methods: {
    myMethod () {
      this.$emit('event') // throws Uncaught TypeError: this.$emit is not a function
    }
  },
  mounted () {
    this.$emit('event') //works perfectly fine
  }
}

Can someone help me in finding what am I doing wrong ?



Solution 1:[1]

Thanks, guys from comments, got me thinking in another way

I am just started learning Vue, and so the problem is pretty stupid

How I was calling the method from the parent component:

childComponent.methods.myMethod()

So I realized I was doing something wrong and after a couple of minutes of googling found the solution in the StackOverflow question

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Unicorn