博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue2.0 keep-alive最佳实践
阅读量:4660 次
发布时间:2019-06-09

本文共 781 字,大约阅读时间需要 2 分钟。

  转自:

1.基本用法

vue2.0提供了一个keep-alive组件用来缓存组件,避免多次加载相应的组件,减少性能消耗

有时候 可能需要缓存整个站点的所有页面,而页面一般一进去都要触发请求的

在使用keep-alive的情况下

将首次触发请求写在created钩子函数中,就能实现缓存,

比如列表页,去了详情页 回来,还是在原来的页面

2.缓存部分页面或者组件

(1)使用router. meta属性

// 这是目前用的比较多的方式

router设置

... routes: [{ path: '/', redirect: '/index', component: Index, meta: { keepAlive: true }},{path: '/common',component: TestParent,children: [{ path: '/test2', component: Test2, meta: { keepAlive: true } } ]}....

// 表示index和test2都使用keep-alive

(2).使用新增属性inlcude/exclude

2.1.0后提供了include/exclude两个属性 可以针对性缓存相应的组件

//其中a,b是组件的name

注意:这种方法都是预先知道组件的名称的

(3)动态判断

includedComponents动态设置即可

 

转载于:https://www.cnblogs.com/EnSnail/p/7124512.html

你可能感兴趣的文章
”语义“的理解
查看>>
210. Course Schedule II
查看>>
月薪3000与月薪30000的文案区别
查看>>
使用spring dynamic modules的理由
查看>>
Leetcode 117 Populating Next Right Pointers in Each Node 2
查看>>
C++ Primer 第四版中文版
查看>>
变量关系
查看>>
NTP工作机制及时间同步的方法
查看>>
近段时间学习html和CSS的一些细碎总结
查看>>
第三章 栈和队列
查看>>
「Vue」v-html生成的图片大小无法调整的解决办法
查看>>
【BZOJ 4665】 4665: 小w的喜糖 (DP+容斥)
查看>>
Git 的 .gitignore 配置
查看>>
Language Integrated Query ----序
查看>>
【HDU】1542 Atlantis
查看>>
解决Android SDK Manager更新时出现问题
查看>>
Android Studio下“Error:Could not find com.android.tools.build:gradle:2.2.1”的解决方法
查看>>
第二章 第四节 添加SWT库
查看>>
docker file
查看>>
总结一些常见的国际标准化组织
查看>>