zoukankan      html  css  js  c++  java
  • 深入理解vue中的slot与slot-scope

    https://segmentfault.com/a/1190000012996217

    https://www.jianshu.com/p/e10baeff888d

    自定义表头: https://www.jianshu.com/p/1b2b0c536980

    1. 匿名插槽

    子组件

    <slot></slot>

    父组件

    <child> XXXXX</child>

    如果不写名字就会直接在子组件匿名插槽渲染

    2. 具名插槽

     

    3. 作用域 插槽

    子组件

    <template>
      <div class="child">   <slot  :data="data"></slot>
      </div>
    </template>
    View Code

    父组件

    <!--第一次使用:用flex展示数据-->
        <child>
          <template slot-scope="user">   
            <div class="tmpl">
              <span v-for="item in user.data">{{item}}</span>
            </div>
          </template>
    
        </child>
    
        <!--第二次使用:用列表展示数据-->
        <child>
          <template slot-scope="user">
            <ul>
              <li v-for="item in user.data">{{item}}</li>
            </ul>
          </template>
    
        </child>
    
        <!--第三次使用:直接显示数据-->
        <child>
          <template slot-scope="user">
           {{user.data}}
          </template>
    
        </child>
    
        <!--第四次使用:不使用其提供的数据, 作用域插槽退变成匿名插槽-->
        <child>
          我就是模板
        </child>
    View Code

    总结: 

     

  • 相关阅读:
    使用opencv显示视频的方法
    使用visual studio 2012 编译opencv2.4.9
    求前100个斐波那契数
    EXTJs前后台交互 常用哦3种方式
    spring 注解
    程序 人生
    ajaxs
    LNMP源码安装脚本
    系统状态统计和查看
    Shell中的${}、##和%%使用范例
  • 原文地址:https://www.cnblogs.com/lhuser/p/11248802.html
Copyright © 2011-2022 走看看