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`)
    }]
}
相关推荐
+VX:Fegn089515 小时前
计算机毕业设计|基于springboot + vue图书管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
阿蒙Amon16 小时前
JavaScript学习笔记:6.表达式和运算符
javascript·笔记·学习
hashiqimiya16 小时前
两个步骤,打包war,tomcat使用war包
java·服务器·前端
小a杰.16 小时前
Flutter 设计系统构建指南
开发语言·javascript·ecmascript
零度@17 小时前
Java中Map的多种用法
java·前端·python
yuanyxh17 小时前
静默打印程序实现
前端·react.js·electron
三十_A18 小时前
如何正确实现圆角渐变边框?为什么 border-radius 对 border-image 不生效?
前端·css·css3
kgduu18 小时前
js之事件系统
javascript
小满zs18 小时前
Next.js第十三章(缓存组件)
前端
前端老宋Running19 小时前
“受控组件”的诅咒:为什么你需要 React Hook Form + Zod 来拯救你的键盘?
前端·javascript·react.js