keepalive keepalive刷新页面
时间: 2023-08-18 10:05:55 浏览: 123
在Vue中,使用keep-alive组件可以缓存组件的实例,以实现不刷新组件但刷新路由的效果。具体的实现方案是将需要使用keep-alive的组件的name加入到keep-alive的include属性中。然后,在组件的after-enter钩子事件中,将当前组件的name添加到keepAliveArr数组中。当需要刷新组件时,可以先从keepAliveArr中移除当前组件的name,然后使用v-if指令将router-view组件从页面中删除,在nextTick事件中重新添加router-view组件,从而实现组件的刷新效果。这样就能够满足不刷新浏览器但刷新路由中的组件的需求了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Vue keepAlive页面强制刷新](https://blog.csdn.net/milugloomy/article/details/109800569)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文