vue3 keep-alive生命周期
时间: 2023-09-19 07:12:32 浏览: 113
在Vue 3中,`keep-alive`组件具有两个新增的生命周期钩子函数:`activated`和`deactivated`。当组件被缓存并重新激活时,`activated`函数会被调用;当组件被缓存并离开时,`deactivated`函数会被调用。这两个钩子函数允许我们在组件被缓存和激活/离开时执行相应的逻辑操作。除了新增的生命周期钩子函数,`keep-alive`组件仍然会遵循普通的Vue组件的生命周期顺序,例如`created`、`mounted`、`updated`和`destroyed`等。所以在使用`keep-alive`组件时,可以根据需要在这些生命周期函数中进行相应的操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Vue生命周期(keep-alive缓存特殊activated(组件激活时)、deactivated(组件停用时))、父子组件的执行顺序](https://blog.csdn.net/muzidigbig/article/details/112696398)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [Vue缓存路由(keep-alive)以及新的生命周期](https://blog.csdn.net/code_dream_wq/article/details/128713825)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文