美文网首页
slot(插槽)的使用

slot(插槽)的使用

作者: 取个帅气的名字真好 | 来源:发表于2018-06-09 00:12 被阅读38次
<!-- 模板 子组件 xxx.vue -->
<template>
  <div>
    <slot></slot>
  </div>
</template>

<!-- 使用 父组件 App.vue -->
<template>
   <div>
    <xxx>
      <span>这里是内容</span>
    </xxx>
 </div>
</template>

<span>这里是内容</span> 对应着 <slot></slot> 这里是默认插槽


具名插槽?当然是有名字的插槽啦。
<!-- 模板 子组件 xxx.vue -->
<template>
  <div>
    <slot name="ccc"></slot>
    <slot name="aaa"></slot>
  </div>
</template>
<!-- 使用 父组件 App.vue -->
<template>
   <div>
      <xxx>
         <span slot="ccc">这里是内容ccc</span>
         <span slot="aaa">这里是内容aaa</span>  
      </xxx>
   </div>
</template>

使用slot对应<slot></solt>标签中的name。 拗口?
理解成 slot="ccc" 对应着 name="ccc"

slot-scope

<!-- 子组件 -->
<template>
  <div class="child">
    // 作用域插槽
    <slot  :data="data"></slot>
  </div>
</template>

 export default {
    data: function(){
      return {
        data: 'luoshushu'
      }
    }
}
<!-- 父组件 -->

<child>
    <span slot-scope="user">{{user.data}}</span>  
      <!-- 渲染出luoshushu -->
</child>

相关文章

  • vue插槽

    vue插槽slot的理解与使用 vue slot插槽的使用介绍及总结

  • 插槽

    插槽的基础使用,

  • Vue插槽:slot、slot-scope与指令v-slot使用

    不具名插槽 具名插槽 v-slotv-slot在组件中使用slot进行占位时,也是在slot标签内使用name 属...

  • 小程序组件插槽

    匿名插槽 使用时,用 slot 属性来将节点插入到不同的slot上。 实名插槽 使用时,用 slot 属性来将节点...

  • Vue01组件化实践-03 插槽 slot

    组件化 slot 插槽 demo github地址:feature/slot 分支 直接上代码体会插槽的使用吧

  • slot是什么?有什么作用?原理是什么?

    slot又名插槽,是Vue的内容分发机制,组件内部的模板引擎使用slot元素作为承载分发内容的出口。插槽slot是...

  • slot(插槽)

    slot又称插槽,是Vue的内容分发机制,组件内部的模板引擎使用slot元素作为承载分发内容的出口。插槽slot是...

  • vue 插槽的使用

    vue 插槽手册 深入理解vue中的slot与slot-scope 插槽的使用其实是很简单首先要明白插槽是使用在子...

  • Vue 小知识点汇总

    插槽slot 如何使用slot的同时传数据(v-slot:name="value") situation: 父页面...

  • 18、Vue3 作用域插槽

    作用域插槽:让插槽内容能够访问子组件中,vue2中作用域插槽使用slot-scope,vue3中使用v-slot ...

网友评论

      本文标题:slot(插槽)的使用

      本文链接:https://www.haomeiwen.com/subject/miezsftx.html