onActivated()

Runs when a KeepAlive-cached component is re-inserted into the DOM.

Since Vue 3.0 Spec ↗

Syntax

onActivated(callback): void

Parameters

NameTypeRequiredDescription
callback () => void No Function run each time the cached component becomes active.

Returns

void — Nothing; registers the hook.

Examples

<script setup lang="ts">
import { onActivated } from 'vue';

onActivated(() => {
  console.log('tab shown again; refresh data if needed');
});
</script>

Notes

Only fires for components rendered inside <KeepAlive>. It runs on initial mount and every subsequent re-activation, making it the place to refresh data or restart timers paused in onDeactivated.