Chapter 96: Vue ‘created’ Lifecycle Hook

Created

This hook is the second step in the component lifecycle (right after beforeCreate), and in the old Options API it was one of the most commonly used hooks. In modern Vue 3 + <script setup> (2026 standard), almost nobody uses created anymore — but you still need to understand it very well because:

  • You will read/maintain legacy Vue 2 / early Vue 3 code
  • Many job interviews (especially in India) still ask about the full lifecycle, including created
  • Older tutorials, books, Stack Overflow answers, and many plugins still show it
  • Vue Devtools still lists it in the lifecycle tab

So let’s go through it step by step — like I’m sitting next to you explaining when it runs, what is ready / not ready, and why 99% of modern developers never touch it.

1. Where created sits in the full lifecycle (Vue 3 timeline)

Here is the exact order of lifecycle hooks:

text

created is the moment when Vue has:

  • Created the component instance
  • Processed data(), props, computed, methods, watch, etc.
  • But has not yet compiled the template or mounted anything to the DOM

2. What is available / NOT available in created?

This is the key table you should memorize — it explains why created was popular in Vue 2 but is rarely needed now.

Feature / Access Available in created()? Reason / Explanation
this Yes Component instance exists and is fully populated
data() / ref() / reactive() Yes data() has already been called, state is reactive
props Yes Props have been resolved & injected
computed Yes Computed properties are created & cached
methods Yes All methods are attached to this
Template / render function No Template has not been compiled yet
DOM / $el / $refs No No rendering or mounting has happened — $el is still undefined
this.$emit Yes You can emit events (but parent might not be listening yet)
this.$parent / $root Yes Parent/child relationship is established
Injected values (provide/inject) Yes Injection has happened

Summary sentence to remember forever:

In created, everything JavaScript-related is ready (data, props, computed, methods, watch), but nothing DOM-related exists yet — no $el, no refs, no rendered elements.

3. Real Example – Seeing What Is / Isn’t Available

vue

Console output when component mounts:

text

→ You see clearly: created has reactive state, props, computed — but no DOM

4. Classic Use-Cases for created (What People Used to Do)

In Vue 2 / early Vue 3, developers used created for:

  • Setting initial state based on props
  • Fetching data that doesn’t depend on DOM
  • Registering global event listeners (rare)
  • Normalizing/transforming props into local data

Example (very common in legacy code)

JavaScript

5. Modern Vue 3 – Why We Almost Never Use created

In <script setup> there is no created hook at all.

The code inside <script setup> runs even earlier than beforeCreate — and that’s usually all you need for initialization.

vue

→ In modern code → you almost never need anything before onBeforeMount → onBeforeMount is the earliest hook you normally use

6. Very Rare Cases Where created Is Still Used (2026)

You will see created in these situations (legacy code):

  1. Old code that wants to normalize props into local data before anything else
  2. Legacy mixins or plugins that need to run very early
  3. Debugging / logging the moment when data & props become available
  4. Some old third-party libraries that hook into created

Realistic 2026 interview answer:

“In modern Vue 3 with <script setup>, we almost never use created — it runs after data & props are ready but before DOM mounting. Most initialization happens at the top level of <script setup> or in onBeforeMount / onMounted. created is mostly seen in legacy Options API code.”

Quick Summary Table – created in 2026

Question Answer / Reality in 2026
When does it run? After data/props/computed/methods are ready, before template compile / mount
Is data/props/computed available? Yes
Is DOM / $el / refs available? No
Is this available? Yes (fully populated instance)
Do modern developers use it? Almost never
Modern replacement Top-level <script setup> code or onBeforeMount
Still asked in interviews? Yes — to check if you understand full lifecycle

Final 2026 Advice

  • In new codenever write created — use top-level code in <script setup> or onBeforeMount
  • When you see created → it means Options API (legacy style)
  • Learn to read it — many jobs, open-source projects, old tutorials still use it
  • Never teach beginners created as useful — it’s mostly trivia now
  • If you ever feel like you need created → 99% chance you’re doing something wrong (ask why you need code after props/data but before DOM)

Your mini homework:

  1. Create a component with beforeCreate, created, mounted logging
  2. Add console.log(this.count) in each → see when it becomes available
  3. Convert to <script setup> → see how much simpler it is (no hooks needed for most init)

Any part confusing? Want to see:

  • Full lifecycle log comparison (Options vs Composition)?
  • Real legacy code using created → how to refactor it?
  • created vs top-level <script setup> code?
  • When created was actually useful (Vue 1 / very old patterns)?

Just tell me — we’ll trace the lifecycle and refactor together step by step 🚀

You may also like...

Leave a Reply

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