1
// 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>

我不知道如何访问<slot/>动态加载的组件。

在上述情况下,this.$slots.default()[0]将是一个对象,它不包含动态组件,只是一个AsyncComponentWrapper

4

0 回答 0