keep-alive使用

两种方式:
Plan1:

  1. app.vue 使用meta作为标识符判断是否需要缓存

    
          
    
2. router.js中 设置meta标签 用来判断是否需要缓存
    
        path: "/service-channel",
        component: ServiceChannel,
        name: "通道配置",
        menuShow: true,
        iconCls: 'iconLeftnav service-channel',
        meta:{keepAlive: true}
```

Plan2: 使用Vue2.1新增属性include/exclude

    
      
    

include 哪些页面需要缓存

exclude 表示不需要缓存的页面

使用include/exclude 属性需要给所有vue类的name赋值(注意不是给route的name赋值),否则 include/exclude不生效
组件中:

export default {
 name:'KeepAlive',
 components: {
   },
 data () {
 return{
}
  },
}

你可能感兴趣的:(vue.js)