H
H
Habr2020-11-23 12:03:10
Vue.js
Habr, 2020-11-23 12:03:10

How to check slot usage?

How can you check the usage of a slot in a component?

<Component>
<template v-slot:header>
....
</template>
</Component>


--- Component code

<template>
  <div :class="classes">
    <slot name="header" />
   </slot>
  </div>
</template>

<script>
export default {
  created () {
    console.log(this.$slots.header) // не работает =(
  }
}
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-11-23
@RozmarinUS

console.log(this.$slots.header) // не работает

Lies, it works. There is a significant difference between "does not work" and "the result of the work is different from the desired", try to understand it.
created () {

What about mounted? Or, if you still don't see the content of the slot, mounted + nextTick?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question