Chapter 91: Vue ‘props’ Option

The props option

This is the official, clean, safe way to pass data from parent to child component — the primary mechanism for parent → child communication in Vue.

Even in 2026 — when almost every new project uses <script setup> + defineProps() — you still need to understand the old props: { … } syntax because:

  • You will read/maintain legacy Vue 2 / early Vue 3 code
  • Many job interviews (especially in India) still ask about Options API
  • Many older tutorials, Stack Overflow answers, and plugins still show it
  • Vue Devtools still displays props in this format

So let’s go through it step by step — like I’m sitting next to you explaining both the old world and why we mostly moved to the new one.

1. What is the props option? (Very simple mental model)

props is an object (or array) that declares which data the parent is allowed to pass to this child component.

Vue takes that declaration and:

  • makes those names available on the component instance (this.user, this.isAdmin)
  • validates the types (in development mode)
  • provides defaults
  • separates them clearly from $attrs (unknown attributes go to $attrs)
JavaScript

After Vue processes this:

  • Parent can pass :user=”currentUser”
  • Inside child → this.user is available (read-only)
  • You never mutate props — child should emit events upward if it needs to change something

2. Real, Complete Example – UserProfileCard with Props

vue

Parent usage example

vue

3. Important Rules & Gotchas (2026 Must-Know)

Rule / Gotcha Correct Behavior / Best Practice
props can be array or object Array: props: [‘user’, ‘isAdmin’] — simple but no types/defaults Object: recommended
Props are read-only Never do this.user.name = ‘new’ → Vue warns / throws in dev mode
Props are reactive Parent changes :user → child auto-updates
Optional props No required: true → can be undefined
Default values default: false / default: () => ({}) (function for objects/arrays)
Type validation type: String, type: Number, type: Object, type: Array, type: Boolean
Custom validator validator(value) { return value > 0 } — throws warning in dev if false
Still used in 2026? Yes — in legacy code, some plugins, interviews, but not in new <script setup> code

4. Modern Vue 3 – Why We Almost Never Use props: { … } Anymore

In <script setup> (the 2026 standard):

vue

→ No props object → No this → No separate defaults/validators (TypeScript does it) → Much cleaner & type-safe

Quick Summary Table – props in 2026

Question Options API (legacy) Composition API (<script setup>) What you should do in new code
How to declare props? props: { user: Object, … } defineProps<{ user: {…} }>() Composition API
Access in template {{ user.name }} {{ user.name }}
Access in methods/computed this.user.name user.name
TypeScript friendly? Poor (manual PropType) Excellent (native types) Use Composition
Still used in 2026? Yes — legacy code, plugins, interviews Almost never (except legacy) Avoid unless maintaining old code

Final 2026 Advice from Real Projects

  • In new projectsnever write props: { … } — use defineProps<…>() in <script setup>
  • When you see props as an object → it means Options API (legacy style)
  • Learn to read Options API — many jobs, open-source projects, tutorials still use it
  • Never teach beginners props option as primary — start with defineProps in <script setup>
  • If migrating old code → gradually convert props: { … } → defineProps<…>()

Your mini homework:

  1. Create the UserProfileCard component above in Options API
  2. Pass different user objects from parent → see props work
  3. Try mutating a prop inside child → see Vue warning in console
  4. Convert it to <script setup> → compare readability & TypeScript support

Any part confusing? Want to see:

  • Full Options API vs Composition API props comparison project?
  • How props looks in Vue Devtools?
  • Common bugs when mutating props?
  • Real component written in both styles?

Just tell me — we’ll convert and compare together step by step 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *