Closed goooogs closed 4 days ago
在首页开启 keepAlive 的情况下,第一次访问首页时不能正常触发 onActivated 钩子
keepAlive
onActivated
代码版本:v4.4.0-30-g7837bac npm: 10.2.3 node: v20.10.0
v4.4.0-30-g7837bac
npm
10.2.3
node
v20.10.0
@/router/index.ts
Dashboard
keepAlive: true
@/views/dashboard/index.vue
script setup
import { onMounted, onActivated, onDeactivated, onUnmounted } from 'vue'
defineOptions({ name: 'Dashboard' })
onActivated(() => console.log('[dashboard] onActivated')) onDeactivated(() => console.log('[dashboard] onDeactivated')) onMounted(() => console.log('[dashboard] onMounted')) onUnmounted(() => console.log('[dashboard] onUnmounted'))
3. `pnpm dev` 启动服务,登录后直接进入首页,控制台只输出 `[dashboard] onMounted`。切换到其它页面能够正常触发 `onDeactivated` 钩子,再回到首页时也能正常触发 `onActivated` 钩子,如下图 <img width="434" alt="image" src="https://github.com/un-pany/v3-admin-vite/assets/8554557/9471e486-baa6-4a96-b543-b58aaa5fc4ac"> ### 补充说明 如果把 `@/layouts/components/AppMain.vue` 中的 `include` 去掉,即:把 `<keep-alive :include="tagsViewStore.cachedViews">` 修改为 `<keep-alive>` 也能正常触发 `onActivated` 钩子 ### 期望 首页开启 `keepAlive` 后,第一次访问首页时能正常触发 `onActivated` 钩子
试了下,没有在router设置keepAlive也是只有打印onMounted
router
onMounted
已修复
问题描述
在首页开启
keepAlive
的情况下,第一次访问首页时不能正常触发onActivated
钩子环境
代码版本:
v4.4.0-30-g7837bac
npm
:10.2.3
node
:v20.10.0
复现步骤
@/router/index.ts
中为Dashboard
添加keepAlive: true
@/views/dashboard/index.vue
的script setup
中添加如下调试代码defineOptions({ name: 'Dashboard' })
onActivated(() => console.log('[dashboard] onActivated')) onDeactivated(() => console.log('[dashboard] onDeactivated')) onMounted(() => console.log('[dashboard] onMounted')) onUnmounted(() => console.log('[dashboard] onUnmounted'))