keepAlive状态保持

1 主要实现原理,状态保持的路由不会执行生命周期的钩子函数,只有第一次进入页面会执行钩子函数。
2 设置当前页面保持keepAlive 直接在路由meta中配置即可
meta{
keepALive:true
} <keep-alive>
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view> actived :这也是一个钩子函数,keepAlive状态保持的页面中生命周期的钩子函数不会触发,但是会触发actived钩子函数,那么这样可操作性就很大了。
2 keepalive 状态保持的页面对应的会又一个actived钩子函数,每次进入页面都会执行的函数,在keepalive状态保持的路由,如果需要加载created,
可以在actived钩子函数中执行,切记第一次进入会执行生命周期函数同时actived钩子函数也会执行 ,
必要情况进行判断,避免两个函数都执行造成数据渲染问题,路由跳转等问题。
3 在局部导航守卫中修改keepalive的值,为true或者false,修改之后同样第一次会执行created 和 actived钩子函数,
需要根据业务需求进行处理。 (代码参考结合实际项目)
演示一 : actived中执行的 activated()
{ if ( this.cancel==='取消订单' )
{ console.log('取消订单');
this.active='已取消'; this.parameterObj.orderStatus ='3,4,5';
this.listDate=[]; if(this.uniqueID)
{ this.listDate=[]; this.parameterObj.uniqueID=this.uniqueID; this.renderOrderList(); }
this.setCancelOrderAction({cancel:''}); }
if(this.$route.params.orderListActive === 1)
{ if(this.uniqueID){ this.parameterObj.uniqueID=this.uniqueID; this.active='待付款'; this.parameterObj.orderStatus='0,2'; this.listDate = [];
this.renderOrderList() } } if(this.$route.params.orderListActive === 0){ if(this.uniqueID){ this.parameterObj.uniqueID=this.uniqueID; this.active='全部';
this.parameterObj.orderStatus='0,1,2,3,4,5'; this.listDate = []; this.renderOrderList() } } 演示二:created中执行的 ,在created中进行判断避免执行created中的函数
if ( this.cancel==='取消订单' ){ return } else if(this.$route.params.orderListActive === 1)
{ return } else if(this.$route.params.orderListActive === 0){ return } else { if(this.uniqueID)
{ console.log(222); this.parameterObj.uniqueID=this.uniqueID; this.listDate = []; this.renderOrderList(); }
else { this.getAppUserInfo(); } }
  
  
  

  

vue 中使用keepAlive状态保持的更多相关文章

  1. vue中使用keepAlive组件缓存遇到的坑

    项目开发中在用户由分类页category进入detail需保存用户状态,查阅了Vue官网后,发现vue2.0提供了一个keep-alive组件. 上一篇讲了keep-alive的基本用法,现在说说遇到 ...

  2. vue中的keep-alive

    本文转载于:https://blog.csdn.net/xum222222/article/details/80322532 转载仅供个人日后学习 https://www.cnblogs.com/ji ...

  3. Vue中 key keep-alive

    keep-alive key <!DOCTYPE html> <html> <head> <title></title> <scrip ...

  4. Vue 中的keep-alive 什么用处?

    keep-alive keep-alive是Vue提供的一个抽象组件,用来对组件进行缓存,从而节省性能,由于是一个抽象组件,所以在v页面渲染完毕后不会被渲染成一个DOM元素 <keep-aliv ...

  5. Vue中使用keep-alive优化网页性能

    用keep-alive包裹路由 当前数据第一次访问时,会被缓存到浏览器缓存当中,若数据无更替,则直接读取缓存中的数据. 使用keep-alive时会存在一个activated的生命周期钩子 只有在la ...

  6. react 实现类似vue中的<keep-alive>的功能,并解决antd-mobile切换回来时的空白

    在移动端的spa页面中,只要使用到了路由就很有必要使用到状态保存的功能,这样才能保证在页面进行切换的时候,让用户可以看到刚才滑动的地方,让用户的体验更加友好.这儿我找到了react-router-ca ...

  7. vue中前进刷新、后退缓存用户浏览数据和浏览位置的实践

    vue中前进刷新.后退缓存用户浏览数据和浏览位置的实践 2018年07月07日 11:58:40 大灰狼的小绵羊哥哥 阅读数:4492   vue中,我们所要实现的一个场景就是: 1.搜索页面==&g ...

  8. 8种Vue中数据更新了但页面没有更新的情况

    目录 1.Vue 无法检测实例被创建时不存在于 data 中的 属性 2. Vue 无法检测'对象属性'的添加或移除 3.Vue 不能检测利用数组索引直接修改一个数组项 4.Vue 不能监测直接修改数 ...

  9. vue中Axios的封装和API接口的管理

    前端小白的声明: 这篇文章为转载:主要是为了方便自己查阅学习.如果对原博主造成侵犯,我会立即删除. 转载地址:点击查看 如图,面对一团糟代码的你~~~真的想说,What F~U~C~K!!! 回归正题 ...

随机推荐

  1. WIN7系统 如何上传文件到FTP服务器中

    https://zhidao.baidu.com/question/214644671.html

  2. tensorflow降低版本

    tensorflow降低版本: pip install tensorflow==1.2.0 查看版本: import tensorflow as tf print(tf.__version__)

  3. springMVC :interceptors

    1.配置拦截器 在springMVC.xml配置文件增加:     <mvc:interceptors>    <!-- 日志拦截器 -->    <mvc:interc ...

  4. package.json bin

    [package.json bin] 1.bin field in your package.json which is a map of command name to local file nam ...

  5. love is ... ...

    16 years old, love is dream.20 years old, love is sex.30 years old, love is marriage. 40 years old, ...

  6. 【Spider】使用CrawlSpider进行爬虫时,无法爬取数据,运行后很快结束,但没有报错

    在学习<python爬虫开发与项目实践>的时候有一个关于CrawlSpider的例子,当我在运行时发现,没有爬取到任何数据,以下是我敲的源代码:import scrapyfrom UseS ...

  7. 获取txt里面的内容

    import flash.net.URLLoader; import flash.net.URLRequest; import flash.events.Event; var txtLoad:URLL ...

  8. poj1019(打表预处理+数学)

    题目链接:http://poj.org/problem?id=1019 题意:对于序列1121231234...,求第i个数字(i<=2147483647). 思路:记第一组为1,第二组为12, ...

  9. 1009 数字1的数量 数位dp

    1级算法题就这样了,前途渺茫啊... 更新一下博客,我刚刚想套用数位dp的模板,发现用那个模板也是可以做到,而且比第二种方法简单很多 第一种方法:我现在用dp[pos][now]来表示第pos位数字为 ...

  10. 修改django后台用户名和密码

    cd到manage.py目录下 python manage.py shell >>from django.contrib.auth.models import User >>u ...