vue中 slot 的使用

  1. slot 的应用场景:
    方便对组件中的模糊节点进行灵活的自定义
  2. 分类
    匿名slot && 匿名slot slot中不接受接受属性及方法的传值,如要实现传值需使用作用域slot
<div class="head">
        <slot></slot>
    </div>
<div class="head">
        <slot name="head-icon"></slot>
    </div>
  1. 作用域slot
<template>
    <div class="head">
        <slot :data></slot>
    </div>
</template>

实现将组件中的data数据传递给slot
在应用这类slot时,外层需要使用template便签包裹,并且 添加属性 scope-slot=“data” 来进行接受

猜你喜欢

转载自blog.csdn.net/qq_35602144/article/details/86348826