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 参考:Vue 'mounted' 生命周期钩子