vue路由缓存

vue路由缓存

在业务场景中有时候需要页面缓存不清空,那么就需要保留缓存(include为需要缓存,而exclude为不缓存,且优先级大于include)

<KeepAlive> 是一个内置组件,它的功能是在多个组件间动态切换时缓存被移除的组件实例。

vue 复制代码
<router-view v-if="!$route.meta.keepAlive"></router-view>
<keep-alive include="页面名称">
  <router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
js 复制代码
export const mainRoutes = {
  path: '/home',
  name: 'home',
  redirect: {
    name: 'welcome'
  },
  component: _import(`modules/home/home`),
  children: [{
      path: '/welcome',
      name: 'welcome',
      meta: {
        title: '首页',
        keepAlive: false //不需要缓存设置为false,需要则为true
      },
      component: _import(`modules/welcome/welcome`)
    }]
}
相关推荐
一 乐1 天前
婚纱摄影网站|基于ssm + vue婚纱摄影网站系统(源码+数据库+文档)
前端·javascript·数据库·vue.js·spring boot·后端
C_心欲无痕1 天前
ts - tsconfig.json配置讲解
linux·前端·ubuntu·typescript·json
清沫1 天前
Claude Skills:Agent 能力扩展的新范式
前端·ai编程
yinuo1 天前
前端跨页面通信终极指南:方案拆解、对比分析
前端
北辰alk1 天前
Vue 模板引擎深度解析:基于 HTML 的声明式渲染
vue.js
北辰alk1 天前
Vue 自定义指令完全指南:定义与应用场景详解
vue.js
yinuo1 天前
前端跨页面通讯终极指南⑨:IndexedDB 用法全解析
前端
北辰alk1 天前
Vue 动态路由完全指南:定义与参数获取详解
vue.js
北辰alk1 天前
Vue Router 完全指南:作用与组件详解
vue.js
北辰alk1 天前
Vue 中使用 this 的完整指南与注意事项
vue.js