vue2.0 keep-active使用方法

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

有时候 可能需要缓存整个站点的所有页面,而页面一般一进去都要触发请求的 在使用keep-alive的情况下 2.缓存部分页面或者组件 (1)使用router.mate属性 /*这是目前用的比较多的方式*/ 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两个属性 可以针对性缓存相应的组件

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

猜你喜欢

转载自blog.csdn.net/MJ1314MJ/article/details/109024273