Skip to content

Component Communication

Props/events/slots cover most parent-child needs. For distant nodes, use provide/inject or Pinia. This lesson covers practical patterns, syntax, and mistakes to avoid.

Patterns for Talking Between Components

Props/events/slots cover most parent-child needs. For distant nodes, use provide/inject or Pinia.

Avoid event buses as your default Vue 3 architecture.

// parent→child: props
// child→parent: emits
// distant: pinia or provide/inject

Communication decision sketch.

Decision Tree

close relation → props/emits; app-wide client → Pinia; injected utilities → provide
  • Prefer Vue 3 + Composition API.
  • Use script setup for SFCs.
  • Keep components focused.
  • Lean on official docs.

Component Communication Cheatsheet

Quick reference for patterns covered in this lesson.

Item Example Purpose
props/emits local Default
slots structure Compose
provide/inject lineage Subtree
pinia global Store
v-model forms Sugar
attrs fallthrough Wrappers

Resist Globalize Early

Lift state only when multiple routes/components need it.

Common Mistakes

  • Event bus spaghetti.
  • Prop drilling 8 levels without slots/store.

Key Takeaways

  • Component Communication is a core Vue skill.
  • Practice in a Vite app.
  • Prefer clarity.
  • Revisit docs for edge cases.

Pro Tip

Write the relationship down: who owns the source of truth?