onActivated() Called When Kept Alive
Last updated: 2026-10-22
onActivated() Called When Kept Alive
onActivated() runs when a component cached by
| Group | Lifecycle Hooks |
|---|---|
| Kind | API |
| Scope | Component |
| Vue Version | 3.0+ |
| SSR Support | Yes |
📝 Syntax
onActivated(() => {
startPolling()
})
⚙️ Arguments
| callback | Function executed on activation |
|---|
Returns:None
▶ Example
Edit the code below and see the live result:
Output:
Switching tabs and back accumulates activations — the component was cached.
💡 Key Points
ℹ️ Note Only fires for components cached by KeepAlive.
💡 Tip Typical uses: resume polling, refetch lists, recompute layout.
⚠️ Warning It also fires on the initial mount — keep the logic idempotent.
🏷️ Related Lifecycle Hooks
💡 Related Cases
More case studies coming soon.
📚 Related Tutorials
❓ FAQ
Q How is it different from onMounted?
A onMounted runs once; onActivated runs on every activation.
Q Does it fire without caching?
A No — it requires a KeepAlive wrapper.
Q Can I fetch data here?
A Yes — the canonical place to refresh data on re-entry.