Chapter 86: Vue Instance Options

Vue Instance Options (also called Options API, component options object, or simply the options object)

This is the classic way of defining a Vue component — the way Vue started, the way millions of tutorials still teach it, and the way many medium/large legacy codebases are still written in 2026.

Even if you personally write 100% <script setup> + Composition API today (which is the modern recommendation), you must understand Options API because:

  • You will read/maintain old code
  • Many job interviews still ask about it
  • Some advanced patterns (mixins, plugins, global components) are still written this way
  • Vue Devtools still shows data/computed/methods in this format

So let’s go through it like a proper classroom session — step by step, with real examples, and clear explanations of what each option actually does.

1. The Basic Shape of a Vue Component in Options API

Every Vue component in Options API is defined as an object with various named properties:

JavaScript

This object is what Vue reads to create the component instance.

2. The Most Important Options (in order of daily usage)

A. name (optional but highly recommended)

JavaScript
  • Used in:
    • Vue Devtools (shows component name instead of “Anonymous”)
    • Recursive components (<user-profile-card /> inside itself)
    • Better error messages & stack traces

2026 tip: Always add name — it costs nothing and saves hours of debugging.

B. props — incoming data from parent

JavaScript

Modern 2026 way (still Options API style but with better syntax):

JavaScript

C. data() — local reactive state

JavaScript
  • Must return a fresh object every time (that’s why it’s a function)
  • All properties become reactive → this.count++ triggers re-render
  • Accessed via this.count (not this.$data.count — although that also works)

D. computed — derived values (cached & reactive)

JavaScript
  • Cached — only re-computes when dependencies change
  • Accessed like data: this.fullName

E. methods — functions you call from template/events

JavaScript
  • Can be called from template: @click=”increment”
  • Have access to this

F. watch — react to data/computed changes

JavaScript

G. Lifecycle Hooks (most important ones)

JavaScript

Modern equivalents in Composition API:

TypeScript

4. Real Example – Full Component in Options API Style

vue

5. Quick Summary Table – Most Important Options (2026)

Option Purpose Modern Composition API equivalent Still used in 2026?
name Component name (Devtools, recursion) defineOptions({ name: ‘…’ }) Yes
props Incoming data defineProps<…>() Yes (legacy)
data() Local reactive state ref(), reactive() Yes (legacy)
computed Derived reactive values computed(() => …) Yes (legacy)
methods Functions normal functions at top level Yes (legacy)
watch React to changes watch(source, callback, options) Yes (legacy)
Lifecycle hooks mounted, beforeUnmount, etc. onMounted, onBeforeUnmount, etc. Yes (legacy)

Final 2026 Advice

  • In new projects → use <script setup> + Composition API (no options object)
  • When you see options object (data(), methods, computed: { … }, watch: { … }) → it is Options API (legacy style)
  • Learn to read Options API — many jobs, many open-source projects, many tutorials still use it
  • Never teach beginners Options API as primary — start with <script setup>
  • If you need to migrate old code → gradually convert to Composition API (Vue 3 supports both side-by-side)

Your mini homework:

  1. Create the UserCard component above in Options API
  2. Change user.age via button → see computed fullName update
  3. Add a watch on user.age
  4. Convert the same component to <script setup> → compare readability

Any part confusing? Want to see:

  • Full Options API vs Composition API side-by-side project?
  • How Options API looks in Vue Devtools?
  • Common bugs when mixing Options + Composition?
  • 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 *