【问题标题】:Lifecycle hook beforeDestroy is not emitted in Vue3Vue3 中未发出生命周期钩子 beforeDestroy
【发布时间】:2023-11-28 07:05:01
【问题描述】:

我使用vue3 beta 18,发现当我删除一个由v-for中的动态组件渲染的组件时,不会发出beforeDestroy。

两者都被停用、销毁。

当我从集合“windows”中删除它时,该组件“消失”了。

<template>
component(v-for="ww in windows" :key="ww.$id" :is="ww.component" v-bind="ww.props")
</template>

【问题讨论】:

    标签: vue.js vuejs3 vue-dynamic-components


    【解决方案1】:

    在 Vue 3 中 beforeDestroy 和被破坏的钩子被替换为 beforeUnmount 和 unmounted https://v3.vuejs.org/api/options-lifecycle-hooks.html#beforeunmount

    【讨论】: