LearnThatStack Ace your next interview
Vue.js · question
Question 4 of 105

What happens in the created vs mounted lifecycle hooks?

beginner
← All Vue.js questions
Re-explain

created runs once the component's reactive state is set up but before any DOM exists. mounted runs after the component's DOM has been created and inserted into the page.

  • created: data and computed properties are set up, and so are methods and watchers. But this.$el is not, because no DOM exists yet. It is a good place for API calls, setting up data, and other logic that does not touch the DOM.
  • mounted: the DOM is fully available, and its synchronous child components are mounted too. Use it to read or change DOM elements and to start third-party libraries that need an element.

created also runs during server-side rendering, while mounted runs only in the browser. That makes mounted the place for browser-only code.

With <script setup>, the setup code runs before both hooks, so it covers the work of created. Use onMounted() for the work of mounted.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Vue.js cheatsheet.

← Back to all Vue.js questions
Pro · $10/mo

90 of 105 Vue.js answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime