Example
Using the beforeUnmount lifecycle hook to create an alert with text taken from inside a <p> element.
html
<script>
export default {
beforeUnmount() {
alert("beforeUnmount: The text inside the p-tag is: " + this.$refs.pEl.innerHTML);
}
}
</script>
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