New Jan 1, 2025

Is it possible to use v-slot in a single file component?

Libraries, Frameworks, etc. All from Newest questions tagged vue.js - Stack Overflow View Is it possible to use v-slot in a single file component? on stackoverflow.com

I'm using vue3

ComponentA.vue

<template>
  <slot name="label"></slot>
  <slot></slot>
</template>

Simply using a template will work.

<template>
  <ComponentA>
    <template #label>
      label
    </template >
    <template #default>
      content
    </template >
  </ComponentA>
</template>

Is there any way to extract two templates into a component? like

<template>
  <ComponentA>
    <ComponentB />
  </ComponentA>
</template>

ComponentA is a component of a library, so I can't modify it.

This is not work. v-slot must be owned by a custom element.

ComponentB.vue

<template>
  <template #label>
    label
  </template >
  <template #default>
    content
  </template >
</template>
Scroll to top