Sometimes, you want to apply specific styles to a component only if it has an event listener attached. For example, you might want to add a cursor: pointer
style to a component only if it has a click
event listener attached.
Vue 3
In Vue 3, you can check the props on the current component instance for that purpose:
Vue 2
In Vue 2, you can use the vm.$listeners
property:
StackBlitz
Try it yourself in this StackBlitz:
If you liked this Vue tip, follow me on X to get notified about new tips, blog posts, and more. Alternatively (or additionally), you can subscribe to my weekly Vue & Nuxt newsletter:
Vue Tip: Watch Slot Changes
You can use the MutationObserver API to react to changes in the slot content.
Nuxt Tip: Cancel Fetch API Request
In Nuxt 3, you can use the `signal` parameter with the globally available `$fetch` helper to cancel an API request.