D
D
Dmitry2019-09-29 10:48:43
Vue.js
Dmitry, 2019-09-29 10:48:43

Is there a way to not output the contents of the slot by default?

There is a component that has several named slots.
One slot has default content. I don't need to render this slot in the component. But if I don't specify it, the default content will be inserted. You cannot opt ​​out of the default content.

<!-- Компонент -->
<template>
  <div>
    <slot name="one">Контент по умолчанию</slot>
    <slot name="two"></slot>
  </div>
</template>

<!-- Родительский компонент -->
<template>
  <div id="app">
    <Component>
      <!-- Содержимое v-slot:one выводится -->
      <template v-slot:two>content</template>
    </Component>
  </div>
</template>

I came up with this hack, but I don't like it
<template>
  <div id="app">
    <Component>
      <template v-slot:one><div v-show="false"></div></template>
      <template v-slot:two>content</template>
    </Component>
  </div>
</template>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2019-09-29
@By_Engine

<slot name="one" v-if="$slots.one"></slot>
<div v-else>Контент по умолчанию</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question