defineEmits()

Declares the events a component can emit inside <script setup>.

Since Vue 3.0 Spec ↗

Syntax

const emit = defineEmits<Events>()

Parameters

NameTypeRequiredDescription
declaration type | string[] No Type argument or array of event names.

Returns

function — A typed emit function.

Examples

<script setup lang="ts">
const emit = defineEmits<{
  submit: [payload: { id: number }];
  cancel: [];
}>();

function save() {
  emit('submit', { id: 1 });
}
</script>

<template>
  <button @click="save">Save</button>
  <button @click="emit('cancel')">Cancel</button>
</template>

Notes

A compiler macro requiring no import, callable only at the top of `<script setup>`. The tuple type syntax types each event's payload. Parents listen with `@submit` / `@cancel`. Pair with defineProps for fully typed component contracts.