Vue.js & Composition API (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What are the essential Vue 3 Lifecycle Hooks?
junior LevelHooksLifecycleVue & Nuxt
In Simple Words:
In the Composition API, lifecycle hooks are imported and invoked inside setup():
onMounted(): Component has finished initial rendering and DOM nodes are accessible. (Fetch initial API data, attach window listeners).onUpdated(): DOM has updated following a reactive state mutation.onUnmounted(): Component has been destroyed and removed from DOM. (Clean up timers, cancel network requests).onErrorCaptured(): Error boundary hook catching child component errors.- Note:
beforeCreateandcreateddo not exist in<script setup>because code inside<script setup>executes during component creation naturally!