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     ]

     

  • 相关阅读:
    Django学习-开篇
    php7 安装event扩展
    nginx try_files 举例详解
    php7.2.3 安装pcntl 扩展
    nginx配置php-pathinfo
    thinkphp3.2.3使用PDO的问题
    niginx参数配置详解(转)
    lnmp编译安装:centos7+nginx-1.12+mariadb10.2+php7.2
    Git 误删本地代码恢复
    Typora + PicGo + Gitee 解放你对图片的管理
  • 原文地址:https://www.cnblogs.com/zxuedong/p/12508655.html
Copyright © 2011-2022 走看看