Skip to main content

What lifecycle hooks are available?

Vue provides a full set of lifecycle hooks, but the set differs between the Options API and the Composition API. In an interview it matters to list both sets.


Lifecycle hooks in the Options API (Vue 2/3)

This is the classic set:

Initialization stage

  • beforeCreate
  • created

Mounting stage

  • beforeMount
  • mounted

Update stage

  • beforeUpdate
  • updated

Unmounting stage

  • beforeUnmount (Vue 3) (in Vue 2 this is beforeDestroy)
  • unmounted (Vue 3) (in Vue 2 this is destroyed)

Components inside <keep-alive>

  • activated
  • deactivated

Lifecycle hooks in the Composition API (Vue 3)

These hooks are imported from Vue and called inside setup() or <script setup>:

js
import { onMounted, onUpdated, onUnmounted } from 'vue'

Initialization

  • onBeforeMount
  • onMounted

Update

  • onBeforeUpdate
  • onUpdated

Unmounting

  • onBeforeUnmount
  • onUnmounted

Keep-alive hooks

  • onActivated
  • onDeactivated

Additional

  • onErrorCaptured - catches errors in child components
  • onRenderTracked - reactivity debugging
  • onRenderTriggered - shows what caused a recalculation
  • onServerPrefetch - for SSR
  • onScopeDispose - cleanup inside composables

Summary (great for an interview)

Options API

beforeCreate created beforeMount mounted beforeUpdate updated beforeUnmount (beforeDestroy) unmounted (destroyed) activated deactivated

Composition API

onBeforeMount onMounted onBeforeUpdate onUpdated onBeforeUnmount onUnmounted onActivated onDeactivated onErrorCaptured onRenderTracked onRenderTriggered onServerPrefetch onScopeDispose

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.