vue3动态组件嵌套

223 阅读1分钟

动态组件嵌套 动态组件是引用的其他的库 里面一层的组件一直没有出来

<component :is="fatherComponentKey">
  <component :is="componentKey">
  </component>
</component>

在父组件(其他库fatherComponentKey这个组件里面)的里面加了<slot> </slot>就可以了

注册组件

  <component :is="tabs[currentTab]">
  </component>
  
import comA from '../comA.vue'
import comB from '../comB.vue'

const currentTab = ref('')
const tabs ={
comA,
comB
}

function selectComA() {
currentTab.value = 'comA'
}
function selectComB() {
currentTab.value = 'comB'
}