Here’s a case where the component needs to decide whether to register an event to take the next step. Vue2 allows this.$listeners to notice events, whereas vue3 doesn’t.

demand

How to notice this.$Listeners [‘custom-click’]

methods

  1. custom-clickNeed to be inemitsRegister or it will be issuedVue warning
emits: ['custom-click'].Copy the code
  1. Vue3 remove $listeners

emits is also unavailable

  1. Vue3 is checking the EMIT eventemits, will also checkpropstheonXXXXattribute

So register at PROPS

props{
    onCustom-click: Function
    // Props should use small hump, horizontal lines should be kept
}
Copy the code
  1. This [‘onCustom-click’] : this[‘onCustom-click’] : this[‘onCustom-click’] : emits

  2. Props uses a small hump, so custom-click is customClick

reference

  • Note the Listeners in vue.js 3