zoukankan      html  css  js  c++  java
  • vue内置组件有哪些?

    1.component:用于动态组件,查看博文vue学习之组件

    <component :is="componentId"></component>

    2.transition:过渡和动画,查看官网文档进入/离开&列表过渡

    <!-- 简单元素 -->
    <transition>
      <div v-if="ok">toggled content</div>
    </transition>

    3.transition-group

    <transition-group tag="ul" name="slide">
      <li v-for="item in items" :key="item.id">
        {{ item.text }}
      </li>
    </transition-group>

    4.keep-alive

    Props:

    • include - 字符串或正则表达式。只有名称匹配的组件会被缓存。
    • exclude - 字符串或正则表达式。任何名称匹配的组件都不会被缓存。
    • max - 数字。最多可以缓存多少组件实例。

    注意:<keep-alive> 要求被切换到的组件都有自己的名字,不论是通过组件的 name 选项还是局部/全局注册。

    <!-- 失活的组件将会被缓存!-->
    <keep-alive>
      <component v-bind:is="currentTabComponent"></component>
    </keep-alive>

    使用:注意,<keep-alive> 用在仅一个直属的子组件被开关的情形。如果在其中有 v-for 则不会工作。

    复制代码
    <!-- 基本 -->
    <keep-alive>
      <component :is="view"></component>
    </keep-alive>
    
    <!-- 多个条件判断的子组件,要求只有一个子元素被渲染 -->
    <keep-alive>
      <comp-a v-if="a > 1"></comp-a>
      <comp-b v-else></comp-b>
    </keep-alive>
    
    <!-- 和 `<transition>` 一起使用 -->
    <transition>
      <keep-alive>
        <component :is="view"></component>
      </keep-alive>
    </transition>
    复制代码

    keep-alive标签属性

    include and exclude:组件有条件地缓存,用逗号分隔字符串、正则表达式或一个数组来表示要匹配的组件名称。

    匹配首先检查组件自身的 name 选项,如果 name 选项不可用,则匹配它的局部注册名称 (父组件 components 选项的键值)。匿名组件不能被匹配。

    复制代码
    <!-- 逗号分隔字符串 -->
    <keep-alive include="a,b">
      <component :is="view"></component>
    </keep-alive>
    
    <!-- 正则表达式 (使用 `v-bind`) -->
    <keep-alive :include="/a|b/">
      <component :is="view"></component>
    </keep-alive>
    
    <!-- 数组 (使用 `v-bind`) -->
    <keep-alive :include="['a', 'b']">
      <component :is="view"></component>
    </keep-alive>
    复制代码

    max:最多可以缓存多少组件实例。一旦这个数字达到了,在新实例被创建之前,已缓存组件中最久没有被访问的实例会被销毁掉。

    <keep-alive :max="10">
      <component :is="view"></component>
    </keep-alive>

    <keep-alive> 不会在函数式组件中正常工作,因为它们没有缓存实例。

    与缓存有关的生命周期钩子activated和deactivated,参考博文:生命周期钩子

    注意:activated 和 deactivated 将会在 <keep-alive> 树内的所有嵌套组件中触发。

    5.slot:查看博文slot

    <slot></slot>
  • 相关阅读:
    MoodNotes产品分析及功能说明书
    C#探秘系列(十)WPF:打开文件选择器选择文件并保存
    C#探秘系列(九)WPF连接Mysql数据库
    C#探秘系列(八)WPF数据绑定
    C#探秘系列(七):XML文件操作(一)
    #安卓杂记(七):自定义控件及属性获取
    C#探秘系列(六)
    安卓问题报告小记(七)
    121. Best Time to Buy and Sell Stock
    566. Reshape the Matrix
  • 原文地址:https://www.cnblogs.com/ygunoil/p/13451670.html
Copyright © 2011-2022 走看看