Skip to content

Using templates slots & conditions when migrating to Vue 3 syntax #8551

Discussion options

You must be logged in to vote

When Vue processes a <template> tag with a v-if or v-else, it's expected to directly contain the elements that should be rendered under that condition. Nested <template> tags are not treated as a single unit in this context.

Here is a solution to warp a <ModalContent> component inside <Modal> component.

<!-- Modal.vue -->

<template>
  <div>
    <slot />
  </div>
</template>
<!-- ModalContent.vue -->

<template>
  <header>
    <slot name="title" />
  </header>

  <main>
    <slot />
  </main>

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

And you should able to use it as following

<!-- App.vue -->

<template>
  <Modal>
    <ModalContent v-if="isLoading">Loading...</ModalCo…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@serkodev
Comment options

@nicooprat
Comment options

Answer selected by nicooprat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants