vue2插槽的父孙组件动态处理

43 阅读1分钟

业务场景

在vue业务组件时。会用到封装的组件插槽。也就是说在业务组件要把插槽插到封装组件(父)里面的还有个封装组件(孙)插槽里,

图示

image.png

业务的组件插槽准确的插到(孙)组件

代码如下,在封装组件里处理的方式用$slots处理

 <parent >
    <template v-slot:current>
      aaa
    </template>
 </parent>
<child>
<template v-for="(_,) in $slots"  v-slot:[_]>
                <slot :name="_"></slot>
              </template>
</child>

如果想对slots的一些插槽处理。可以处理成计算属性的方式