zoukankan      html  css  js  c++  java
  • 缓存组件

    缓存组件的新用法

    1.缓存组件的介绍用来保留组件的状态,避免数据的污染

    2.缓存组件的用法

     1 <!-- 组件内部-->
     2 <keep-alive>
     3     <router-view v-if="$route.meta.keepAlive">
     4         <!-- 这里是会被缓存的视图组件,比如 Home! -->
     5     </router-view>
     6 </keep-alive>
     7  
     8 <router-view v-if="!$route.meta.keepAlive">
     9     <!-- 这里是不被缓存的视图组件,比如 Edit! -->
    10 </router-view>
     1 //router/index.js
     2     export default [
     3       {
     4         path: '/',
     5         name: 'home',
     6         component: Home,
     7         meta: {
     8           keepAlive: true // 需要被缓存
     9         }
    10       }, {
    11         path: '/:id',
    12         name: 'edit',
    13         component: Edit,
    14         meta: {
    15           keepAlive: false // 不需要被缓存
    16         }
    17       }
    18     ]

    3.组件缓存的另一种用法

      注意当组件在缓存组件中切换:他的activateddeactivated这俩个声明周期函数将会被执行

    1 <!--只要将缓存的组件的name名称放到include里面即可-->
    2 <!--不需要缓存的组件的name名称放到exclude里面即可-->
    3 <keep-alive>
    4     <router-view :exclude="[]" :include="['home']">
    5     </router-view>
    6 </keep-alive>
     1 //router/index.js
     2     export default [
     3       {
     4         path: '/',
     5         name: 'home',
     6         component: Home
     7       }, {
     8         path: '/:id',
     9         name: 'edit',
    10         component: Edit
    11       }
    12     ]

     

  • 相关阅读:
    Linux软件安装
    虚拟地址和物理地址
    python 读写txt文件
    python 浮点数保留几位小数
    Contiki源码结构
    Contiki Rtimer 模块
    Contiki Ctimer模块
    Contiki Etimer 模块
    Contiki Timer & Stimer 模块
    Contiki clock模块
  • 原文地址:https://www.cnblogs.com/zxuedong/p/12508655.html
Copyright © 2011-2022 走看看