Skip to content

Vue Props

Props declare the public inputs of a component. Treat them as read-only. This lesson covers practical patterns, syntax, and mistakes to avoid.

Passing Props

Props declare the public inputs of a component. Treat them as read-only.

In script setup, use defineProps with runtime or types.

<script setup lang="ts">
const props = defineProps<{ title: string; count?: number }>()
</script>
<template>
  <h2>{{ title }}</h2>
</template>

Typed props with defineProps.

Validation

required, types, defaults, validators (runtime declarations)
  • Prefer Vue 3 + Composition API.
  • Use script setup for SFCs.
  • Keep components focused.
  • Lean on official docs.

Vue Props Cheatsheet

Quick reference for patterns covered in this lesson.

Item Example Purpose
defineProps macro Setup
defaults withDefaults Optional
one-way down Dataflow
boolean presence Attrs
fallthrough attrs Non-prop
TS type-based Prefer

withDefaults

Provide default values for type-based props.

Common Mistakes

  • Mutating props in children.
  • Huge prop bags that should be slots/provide.

Key Takeaways

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

Pro Tip

If many booleans configure markup, consider slots instead.