onBeforeUnmount()
Registers a callback run just before the component is unmounted.
Syntax
onBeforeUnmount(callback): void Parameters
| Name | Type | Required | Description |
|---|---|---|---|
callback | () => void | No | Function run while the component is still fully functional. |
Returns
void — Nothing; registers the hook.
Examples
<script setup lang="ts">
import { onBeforeUnmount } from 'vue';
onBeforeUnmount(() => {
console.log('component still mounted; saving state...');
});
</script>
Notes
Fires before teardown begins, while the instance and DOM are still intact, so
you can read final state or persist data. For releasing resources after
removal, use onUnmounted instead.