Vue 'beforeUnmount' Lifecycle Hook


Example

Using the beforeUnmount lifecycle hook to create an alert with text taken from inside a <p> element.

<script>
export default {
  beforeUnmount() {
    alert("beforeUnmount: The text inside the p-tag is: " + this.$refs.pEl.innerHTML);
  }
}
</script>
Run Example »

Definition and Usage

The beforeUnmount lifecycle hook happens right before the component is removed from the DOM.

When running code in the beforeUnmount hook, the component is still fully functional.


Related Pages

Vue Tutorial: Vue Lifecycle Hooks

Vue Tutorial: The 'beforeUnmount' Hook

Vue Reference: Vue 'mounted' Lifecycle Hook


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.