Skip to content

Get width of slot from useSlot() #6726

Discussion options

You must be logged in to vote

It looks like this other issue is related: #2196

Try it, you'd have to use a render function.

Playground example

<template>
 <div>
    <button @mouseover="state.show = true" @mouseleave="state.show = false">
      hover me
    </button>
    <div v-if="state.show">
      <RenderTestSlot />      
    </div>
  </div>
</template>

<script setup>
import { reactive, watch, useSlots, nextTick, computed, h, Fragment } from 'vue'

const slots = useSlots();
const state = reactive({
  show: false
})  

const RenderTestSlot = computed(() => h(Fragment, slots.test ? slots.test() : []));

watch(() => state.show, () => {
  if (state.show) {
    nextTick(() => {
      console.log(RenderTestSlot.value.chi…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@d0peCode
Comment options

@Caffeine19
Comment options

@Sight-wcg
Comment options

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