Next.js starter your AI actually understands. Ship internal tools in days not weeks. Pre-order $199 $499 → [Get it now]

How to use $emit with parameters in Vue

Using $emit with parameters enables powerful parent-child communication by passing data and event details from child to parent components. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented $emit with parameters in thousands of Vue components for enterprise applications. From my expertise, the most effective approach is using descriptive event names with structured parameter objects. This method provides clear component APIs and maintainable parent-child communication.

Use $emit with event name and parameter objects to pass data to parent components.

<!-- Child Component -->
<template>
  <button @click="handleClick">Click me</button>
</template>

<script setup>
const emit = defineEmits(['button-clicked'])

const handleClick = () => {
  emit('button-clicked', {
    timestamp: new Date().toISOString(),
    data: 'button data'
  })
}
</script>

<!-- Parent Component -->
<template>
  <ChildComponent @button-clicked="handleButtonClick" />
</template>

<script setup>
const handleButtonClick = (eventData) => {
  console.log('Received:', eventData)
}
</script>

The $emit method accepts the event name as first parameter, followed by any number of additional parameters. Pass structured objects for complex data rather than multiple separate parameters. The parent component receives these parameters in its event handler function arguments.

Best Practice Note:

This is the same approach we use in CoreUI Vue components for component communication. Use descriptive event names and structured parameter objects for maintainable component APIs.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
What is the difference between sort and toSorted in JavaScript?
What is the difference between sort and toSorted in JavaScript?

How to check if an element is visible in JavaScript
How to check if an element is visible in JavaScript

How to validate an email address in JavaScript
How to validate an email address in JavaScript

How to Clone an Object in JavaScript
How to Clone an Object in JavaScript

Answers by CoreUI Core Team