vue2.0 keep-active使用方法
2017-03-11 17:52
1046 查看
本文转自:https://segmentfault.com/a/1190000008123035
有时候 可能需要缓存整个站点的所有页面,而页面一般一进去都要触发请求的
在使用keep-alive的情况下
router设置:
(2).使用新增属性inlcude/exclude
2.1.0后提供了include/exclude两个属性 可以针对性缓存相应的组件
注意: 这种方法都是预先知道组件的名称的
(2)动态判断
includedComponents设置为变量,动态改变即可
1、基本用法:
vue2.0提供了一个keep-alive组件用来缓存组件,避免多次加载相应的组件,减少性能消耗<keep-alive> <component> <!-- 组件将被缓存 --> </component> </keep-alive>
有时候 可能需要缓存整个站点的所有页面,而页面一般一进去都要触发请求的
在使用keep-alive的情况下
<keep-alive> <router-view></router-view> </keep-alive>
2.缓存部分页面或者组件
(1)使用router.mate属性/*这是目前用的比较多的方式*/ <keep-alive> <router-view v-if="!$route.meta.notKeepAlive"></router-view> </keep-alive> <router-view v-if="$route.meta.notKeepAlive"></router-view>
router设置:
... routes: [ { path: '/', redirect: '/index', component: Index, mate: { keepAlive: true }}, { path: '/common', component: TestParent, children: [ { path: '/test2', component: Test2, mate: { keepAlive: true } } ] } .... //表示index和test2都使用keep-alive
(2).使用新增属性inlcude/exclude
2.1.0后提供了include/exclude两个属性 可以针对性缓存相应的组件
<!-- comma-delimited string --> <keep-alive include="a,b"> <component :is="view"></component> </keep-alive> <!-- regex (use v-bind) --> <keep-alive :include="/a|b/"> <component :is="view"></component> </keep-alive> /*其中a,b是组件的name */
注意: 这种方法都是预先知道组件的名称的
(2)动态判断
<keep-alive :include="includedComponents"> <router-view></router-view> </keep-alive>
includedComponents设置为变量,动态改变即可
相关文章推荐
- YII2.0 Activeform表单组件的使用方法
- 使用vue的时候我们使用keep-alive会将页面缓存的解决方法
- yii2.0 Activeform表单部分组件使用方法
- vue解决使用webpack打包后keep-alive不生效的方法
- 使用vue2.0创建的项目的步骤方法
- yii2.0 Activeform表单部分组件使用方法
- vue2.0 datepicker使用方法
- Vue2.0 UI框架ElementUI使用方法详解
- YII2.0 Activeform表单组件的使用方法
- vue2.0自定义指令的使用方法
- (vue.js)vue 父组件使用keep-alive和infinite-scroll导致在子组件触发父组件的infinite-scroll方法
- vue2.0设置proxyTable使用axios进行跨域请求的方法
- vue2.0 使用element-ui里的upload组件实现图片预览效果方法
- Vue2.0 keep-alive 后组件不使用缓存
- yii2.0 Activeform表单部分组件使用方法
- yii2.0 Activeform表单部分组件使用方法
- yii2.0 Activeform表单部分组件使用方法
- vue 2.0中使用axios遇到问题的解决方法
- YII2.0 Activeform表单组件的使用方法
- [转]NUnit2.0详细使用方法