两种方式:
Plan1:
app.vue 使用meta作为标识符判断是否需要缓存
<keep-alive> <router-view v-if="$route.meta.keepAlive"></router-view> </keep-alive>
2. router.js中 设置meta标签 用来判断是否需要缓存
path: "/service-channel",
component: ServiceChannel,
name: "通道配置",
menuShow: true,
iconCls: 'iconLeftnav service-channel',
meta:{keepAlive: true}
```
Plan2: 使用Vue2.1新增属性include/exclude
<keep-alive include="KeepAlive">
<router-view ></router-view>
</keep-alive>
include 哪些页面需要缓存
exclude 表示不需要缓存的页面
使用include/exclude 属性需要给所有vue类的name赋值(注意不是给route的name赋值),否则 include/exclude不生效
组件中:
export default {
name:'KeepAlive',
components: {
},
data () {
return{
}
},
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。