keep-alive使用
文章目录
两种方式:
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{
}
},
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论