How to access slot dynamic component in vue3?

571 Views Asked by At
// main.vue
<template>
    <window v-for="app in apps">
      // `app` is defined by `defineAsyncComponent(()=> import('path/to/app.vue'))`
      <component :is="app"></component>
    </window>
</template>
//window.vue
<template>
    <div class="window" @click="click">
      <slot/>
    </div>
</template>
<script>
...
methods:{
    click (){
        // I need to access the `app` dynamic component here!
        const app = this.$slots.default()[0];
    }
}
...
</script>

I dont know how to access <slot/> component which is dynamic loaded.

In above case,this.$slots.default()[0] will be an object and it hasn't contain the dynamic component,just a AsyncComponentWrapper

1

There are 1 best solutions below

0
On

One way to access the component is by checking .type.__asyncResolved. It is not a clean way but that is what is available for now.

enter image description here