Skip to content
Back to skills

Vue Component Events

ASecurity

> Communicate from child to parent components using emits and defineEmits

  • 20 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 11, 2026
businesstypescriptvue

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned September 11, 2026

npx -y skills add Intense-Visions/harness-engineering --skill vue-component-events --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Vue Component Events?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Vue Component Events
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/intense-visions-vue-component-events/badge)](https://www.skillsdirectory.com/skills/intense-visions-vue-component-events)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Vue Component Events

> Communicate from child to parent components using emits and defineEmits

## When to Use

- A child component needs to notify its parent of user actions or state changes
- Implementing form inputs, buttons, or interactive components that report values upward
- Building reusable components with a clear input/output contract (props down, events up)

## Instructions

1. Declare events with `defineEmits<{ eventName: [payload: Type] }>()` in `<script setup>`.
2. Emit events with `emit('eventName', payload)`.
3. The parent listens with `@event-name="handler"` (kebab-case in template).
4. Always type your emit payloads for compile-time safety.

```vue
<!-- ChildButton.vue -->
<script setup lang="ts">
const emit = defineEmits<{
  click: [id: number];
  update: [value: string];
}>();
</script>

<template>
  <button @click="emit('click', 42)">Click</button>
</template>

<!-- Parent.vue -->
<ChildButton @click="handleClick" @update="handleUpdate" />
```

5. Use `v-model` as syntactic sugar for an `update:modelValue` event pattern.
6. Validate emits at runtime by passing a validation function to `defineEmits`.

## Details

Vue's event system follows a "props down, events up" pattern. Parents pass data to children via props; children notify parents via emitted events. This creates a clear, unidirectional data flow that is easy to trace and debug.

**Trade-offs:**

- Events only travel one level up — for deeply nested communication, use `provide`/`inject` or a store
- Untyped emits (array syntax) provide no compile-time safety — always use the typed syntax
- Event names are strings — typos are caught at runtime, not compile time (unless using TypeScript with `defineEmits`)

**When NOT to use:**

- For deeply nested parent-child communication — use `provide`/`inject` or Pinia
- For sibling component communication — use a shared store or event bus (though event buses are discouraged in Vue 3)
- When the parent does not need to know about the event — side effects belong in the child

## Source

https://patterns.dev/vue/component-events

## Process

1. Read the instructions and examples in this document.
2. Apply the patterns to your implementation, adapting to your specific context.
3. Verify your implementation against the details and edge cases listed above.

## Harness Integration

- **Type:** knowledge — this skill is a reference document, not a procedural workflow.
- **No tools or state** — consumed as context by other skills and agents.

## Success Criteria

- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.

Files in this skill

  • SKILL.md2.6 KB
  • skill.yaml657 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…