Vue 更改keep-alive源码,满足条件性缓存(多个页签之间切换缓存,关闭页签重新打开不缓存)

Vue3多路由指向同一组件 实现keep-alive缓存页面的解决方案 需求:十几个路由使用的组件是同一个,从一个页面到另一个页面或者其他页面的时候,让之前输入的数据还存在。 阅读详情

应用场景
当系统打开多个页签时,多个页签之间切换去做缓存,关闭页签重新打开该页签不缓存。

解决方案
更改 vue keep-alive源码

1、制造一个唯一的key值,在路由参数里面加一个时间戳

1.1 因keep-alive 使用组件名称name值作为唯一的key值去做条件缓存,但是该项目因书写不规范导致组件的name值不是唯一的。在路由的参数

    里面增加一个时间戳

        // 当点击系统左侧菜单的时候加时间戳

         select(url) {

             //先把打开的页签全部放到store里面

            //在打开页签里面找index原因是:找到已经打开过的页签的index,避免打开重复的多个页签
            const isHas = this.$store.state.multiTabPages.findIndex((val)=>{
                return val.name === url
            })
            if(isHas === -1) {
                this.$router.push({name:url, query: {
                    timeStr: new Date().getTime()
                }});
            }else {

               //如果找到已经打开过的这个页签,那就跳转到它原来的最初打开的页签页面
                this.$router.push({name:url, query: {
                    timeStr: this.$store.state.multiTabPages[isHas].query.timeStr
                }});
            }
        },

2、给自定义的keep-alive组件唯一的key值

 2.1 从依赖vue包里面找到keep-alive组件,拿到源码。在全局的组件里面创建一个自定义的keep-alive组件,注意组件名不要和vue自带的keep-alive组件名称相同会有冲突。

 2.2 源码是用ts写的,如果你的项目不支持ts,要先改成js,主要改的是render里面的逻辑。

 // keep-alive使用的是name值做匹配缓存,如下:

 const name = getComponentName(componentOptions)
    const { include, exclude } = this
    if (
      // not included
      (include && (!name || !matches(include, name))) ||
      // excluded
      (exclude && name && matches(exclude, name))
    ) {
      return vnode
    }


    const { cache, keys } = this
    const key = vnode.key == null
      // same constructor may get registered as different local components
      // so cid alone is not enough (#3269)
      ? componentOptions.Ctor.cid + (componentOptions.tag ? `::${componentOptions.tag}` : '')
      : vnode.key

2.3   把关闭页签的路由信息存入store中,在自定义的keep-alive组件中拿到关闭页签的路由信息

const slot = this.$slots.default // 获取默认插槽
const vnode = getFirstComponentChild(slot) // 获取第一个子节点
const componentOptions = vnode && vnode.componentOptions
if (componentOptions) {
  const { cache, keys } = this
  const route = this.$route  
  const key = route.fullPath  //拿到打开的页签的唯一key值(在路由里面加的时间戳和path组成的一个唯一的key值)


  // 拿到关闭页签的路由信息
  const removeRoute = this.$store.state.removeRoute || []
  if(removeRoute && removeRoute.length > 0){
    let tempKeys = JSON.parse(JSON.stringify(this.keys))
    let diff = tempKeys.filter((val) => { return !removeRoute.includes(val)})
    this.keys = JSON.parse(JSON.stringify(diff))
    for (const key in this.cache) {
      // 在缓存的cache对象里面移除掉已关闭的页签的信息
      if(removeRoute.includes(key)) {
        delete this.cache[key];
      }
    }
  }
  // 如果key对应的vnode存在,则更新key值
  if (cache[key]) {
    vnode.componentInstance = cache[key].componentInstance
    remove(keys, key)
    keys.push(key) // 调整key排序
  } else {
    // 否则将vnode存入缓存
    cache[key] = vnode
    keys.push(key)
  }
  vnode.data.keepAlive = true
}
return vnode || (slot && slot[0])

3、使用自定义的keep-alive组件


        
实现动态路由缓存:解决不同路由复用同一组件时,vue缓存(keep-alive) 同时删除的问题 (解决缓存同一个组件不同的页面,如何移除某个页面时不影响其他同组件的页面的问题) 本文主要解决缓存同一个组件不同的页面,如何移除某个页面时不影响其他同组件的页面的问题。更改keep-alive源码使自定义key为path,根据页面路由判断缓存。动态路由页面,同时打开多个详情页(例:路由为/detail/:id的两个详情页/detail/1,/detail/2),当关闭/detail/1标签页时,/detail/2的页面缓存也会被清除。 阅读详情

相关推荐

Yakit WebFuzzer标签页意外关闭:Electron应用状态管理与数据持久化实战解析

在现代桌面应用开发中,状态管理与数据持久化是保障用户体验和功能可靠性的核心技术。其原理在于,应用需要将用户操作产生的临时数据(状态)进行有效组织,并在特定时机(如页面切换、应用关闭)将其保存至本地存储或数据库,确保数据不丢失。这项技术的核心价值在于提升软件的健壮性和用户的工作效率,尤其在安全测试、数据编辑等需要长时间交互的场景中至关重要。以基于Electron框架构建的跨平台应用为例,其结合了Web技术的灵活性与本地应用的能力,但同时也带来了状态管理链路的复杂性。在渗透测试工具等工程实践中,状态同步失败、存

weixin_34258838的博客 361

前端犄角旮旯,非常规面试题总结(不断更新....)

27、判断类型的方式有哪些?1、typeof操作符:用来检测数据的类型,返回的是一个表示类型的字符串。2、instanceof操作符:用来检测对象是否为指定的构造函数的实例。3、方法:可以返回对象的准确类型。4、方法:用来判断一个变量是否为数组。(一)typeof和instanceof区别typeof返回的是一个字符串,表示变量的数据类型,可能的返回值有numberstringbooleanfunctionundefinedobject。instanceof返回的是一个布尔值,true或。

qq_51398495的博客 1666

Vue2.0 实现页面缓存和不缓存的方式

今天小编就为大家分享一篇Vue2.0 实现页面缓存和不缓存的方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

从病毒分析到安全研究:手把手教你用OD破解加壳程序的反调试机制

本文深入探讨了如何识别并绕过加壳程序的反调试机制,特别是针对使用IsDebuggerPresent等API检测的防护手段。通过实战案例和工具链配置,详细介绍了逆向工程中的关键技巧,包括内存补丁、硬件断点定位OEP等,帮助安全研究人员有效突破软件保护技术。

tgb345678的博客 825

时空数据建模的跨节点联邦图神经网络:KDD21 Cross-Node Federated Graph Neural Network for Spatio-Temporal Data Modeling

前言 联邦学习(FL)虽然已经被广泛研究,但是对复杂的时空依赖关系进行建模以提高预测能力仍然是一个开放的问题。此外目前最优的时空预测模型假定对数据的访问不受限制,忽略了对数据共享的限制。基于此,本文提了一个基于图联邦学习的时空数据模型 Cross-Node Federated Graph Neural Network (CNFGNN),该模型在跨节点联邦学习的约束下,使用基于图神经网络(GNN)的架构对底层图结构进行编码,属于结构化联邦的一种,每个本地模型利用私有数据进行学习,并保持分散性。CNFGNN

qq_56027260的博客 1810

40分钟快速入门Dart基础(上)

针对final 和const 理解的有点模糊的可以参考这篇文章: 可以参考这里Flutter 知识梳理(Dart)-Dart中static final const 区别看是不是超级好上手,好操作~其实Dart的整个学习起来还是蛮简单的,对于有基础的老司机更简单一些。分分钟敲起来~这篇文章就简单的介绍到这里如何短时间快速入门Dart,避免入坑。由于是想让大家快速入门Flutter,所以针对上面的这些章节我们讲解的只是一些在开发Flutter 过程中常用的一些方法和函数。

qq_7813180 4572

Python爬虫实战:模拟登录B站 – 处理Cookie和加密参数

由于B站在登录过程中采用了多种安全措施,包括加密的请求参数和cookie验证,模拟登录成为一项具有挑战性的任务。首先,我们需要获取B站的登录页面,并解析出其中的CSRF令牌和其他隐藏的字段。B站的登录接口通常会包含一些动态的加密参数,我们需要在登录前通过GET请求获取这些信息。本文详细介绍了如何使用Python模拟登录B站,解决加密参数的处理、图形验证码的识别以及登录后的数据抓取。库中的加密方法加密登录请求中的密码。一旦登录成功,我们可以通过维护会话状态,抓取登录后的数据,如个人主页、评论、观看记录等。

2201_76125261的博客 1309

SwinTransformer改进(5):与CBAM结合的视觉模型

这个模型的核心思想是将Swin Transformer的强大特征提取能力与CBAM的注意力机制相结合,以提升模型对重要特征的关注度。​​CBAM模块​​:包含通道注意力和空间注意力两个子模块​​Swin Transformer主干网络​​:作为基础特征提取器​​集成结构​​:在Swin Transformer的不同阶段插入CBAM模块使用移动窗口(Moving Window)机制减少计算量层次化设计,特征图逐渐缩小,通道数逐渐增加在不同阶段使用Patch Merging进行下采样。

2401_82355416的博客 688

【maven】maven 3.8.1 版本编译java 17的项目报错 java.lang.ExceptionInitializerError to make field private com.s

排查发现一切正常,但是内网就是不行,然后我就想把我的程序从java 11 改成java 17,然后执行编译的时候报错。这个问题是我们内网java代码升级,项目比较复杂,是从java 8 升级到java 17,然后报错。maven-compiler-plugin 3.8.1 版本编译java 17的项目,报错。然后查看一下这个项目的lombok,结果发现还是老的版本。怀疑是不是这个问题呢?使用最新的版本就可以了。

九师兄 781

华为MetaERP在财务模块(GL/AP/AR/FA)及子账模块效率优化、月末关账加速、与外部系统对账方面,已形成一套**“并行+实时+智能化”**的完整技术方案

华为MetaERP推出"并行+实时+智能化"技术方案,显著提升财务模块效率:1)采用三级并行策略和内存计算,使子账模块单任务处理时间从142分钟降至9分钟;2)通过并行关账架构将月末关账时间从68小时压缩至7.2小时;3)运用AI智能对账提升效率50%,并支持异步流程和区块链审计。典型场景测试显示月结耗时下降89%,CPU利用率提升116%。方案建议分阶段实施,注意依赖分析、任务粒度设计和性能监控,避免过度并行。该方案已有效解决大型集团财务处理效率低、关账慢、对账难等痛点。

金牌架构师 561

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

上一篇: Vue:keep-alive的用法总结
下一篇: Vue开发规范细节
相约在一年四季
博客等级 码龄8年 12粉丝 30原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值