Vue beforeUnmount 生命周期钩子
实例
使用 beforeUnmount 生命周期钩子创建一个警报,其中的文本取自 <p> 元素内部。
<script>export default {beforeUnmount() {alert("beforeUnmount: The text inside the p-tag is: " + this.$refs.pEl.innerHTML);}}</script>
定义与用法
beforeUnmount 生命周期钩子发生在从 DOM 中移除组件之前。
当在 beforeUnmount 钩子中运行代码时,该组件仍然完全正常工作。
关联页面
Vue 教程: Vue 生命周期钩子
Vue 教程: beforeUnmount 钩子
Vue 参考引用: mounted 钩子