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`)
    }]
}
相关推荐
万少27 分钟前
使用Trae轻松安装openclaw的教程-附带免费token
前端·openai·ai编程
颜酱44 分钟前
一步步实现字符串计算器:从「转整数」到「带括号与优化」
javascript·后端·算法
浪浪山_大橙子44 分钟前
OpenClaw 十分钟快速,安装与接入完全指南 - 推荐使用trae 官方 skills 安装
前端·人工智能
忆江南1 小时前
iOS 可视化埋点与无痕埋点详解
前端
离开地球表面_991 小时前
金三银四程序员跳槽指南:从简历到面试再到 Offer 的全流程准备
前端·后端·面试
_柳青杨1 小时前
跨域获取 iframe 选中文本?自己写个代理中间层,再也不求后端!
前端
比尔盖茨的大脑1 小时前
事件循环底层原理:从 V8 引擎到浏览器实现
前端·javascript·面试
天才熊猫君1 小时前
Vue3 命令式弹窗原理和 provide/inject 隔离机制详解
前端
bluceli1 小时前
Vue 3 Composition API深度解析:构建可复用逻辑的终极方案
前端·vue.js
程序员ys1 小时前
前端权限控制设计
前端·vue.js·react.js