惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tenable Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
L
LINUX DO - 热门话题
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
H
Hacker News: Front Page
C
Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Martin Fowler
Martin Fowler
Help Net Security
Help Net Security
Scott Helme
Scott Helme
U
Unit 42
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyberwarzone
Cyberwarzone
Microsoft Security Blog
Microsoft Security Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
Cloudbric
Cloudbric
Simon Willison's Weblog
Simon Willison's Weblog
A
Arctic Wolf
云风的 BLOG
云风的 BLOG
V
Vulnerabilities – Threatpost
Stack Overflow Blog
Stack Overflow Blog
T
Tor Project blog
O
OpenAI News
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Exploit Database - CXSecurity.com
MyScale Blog
MyScale Blog
罗磊的独立博客
美团技术团队
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
P
Privacy International News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Recorded Future
Recorded Future
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Blog — PlanetScale
Blog — PlanetScale

博客园 - 雪莉06

antd vue 树形表格 vue中实现页面全屏和指定元素全屏 screenfull全屏组件的基本使用 网页导出EXCEL格式数据,长数字变为科学计数法的解决方法 dedecms织梦自定义表单导出到excel的方法 织梦dede:arclist按最新修改排序orderby=pubdate无效的解决方法 vue-router报错:Uncaught (in promise) NavigationDuplicated {_name: ‘NavigationDuplicated‘, name: ‘Navig nvm的安装和使用(转) elementUI 的 input无法输入bug解决 vue数字翻牌效果 j-modal的 slot="footer" 失效 v-if判断页脚按钮 帝国CMS后台登录空白怎么办?如何修改成https ES6两个数组进行比较 element ui form表单 表格下嵌套动态表格,新增行,删除行 vue 父子组件传值报错:this.$emit is not a function 解决 dede列表页调用二三级导航栏(转载) a-table 鼠标滑过显示小手,当前行可点击(转载) echarts折线图使用dataZoom,切换数据时渲染异常,出现竖线bug vue里面修改title样式
vue2 jeecgBoot keepalive 解决方案
雪莉06 · 2025-08-01 · via 博客园 - 雪莉06

经公司项目测试,jeecgboot vue2 开源框架,目前只支持一、二级路由缓存,三级及以上路由在 tabs 切换时会丢失数据。

因为没有缓存到页面,导致每次进入页面都会重新初始化。

解决方案

在处理解决方案前,请先确认下该路由菜单是否已经在菜单页面上开启缓存路由的按钮

1)框架层面

首先针对以上问题,我们需要在创建路由前,对当前页面的路由层级进行处理。

比如:当需要对三级路由进行 keepalive 操作时,我们在 router.beforeEach 获取到路由层级列表的中间层级其实只是个菜单,并没有什么真实的使用场景。因此我们可以删除掉中间的层级菜单,只保留第一条的首页数据和最后一条的页面路由数据即可。

src/router/index.js

router.beforeEach((to, from, next) => {
+    if (to.matched && to.matched.length > 3 && to.meta.keepAlive) {
+        to.matched.splice(1, to.matched.length - 3)
+    }
  next()    
})

解决了框架层面的问题,这是我们怀着尝试的内心进行测试,发现有些小伙伴可以,但是还是有些无法实现 keepalive;或者说有些页面可以,但是有些页面不行。

2)代码问题

根据 vue 官网keepalive 说明:

keepalive 会根据组件的 name 选项进行匹配,所以组件如果想要条件性地被 KeepAlive 缓存,就必须显式声明一个 name 选项。

说明在开发页面级组件时,需要给页面增加一个 name 属性。这个 name 属性需要和路由菜单的配置一致,才会使 keepalive 生效。

因此我们在定义这个 name 时,可以先看下页面初始化时调用的接口 /sys/permission/getUserPermissionByToken

看下每个路由菜单下 meta.componentName 数据。只要 namemeta.componentName 保持一致。即可实现 keepalive

作者:书航
链接:https://juejin.cn/post/7311625031972225050
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。