Search code examples
vue.jselement-ui

[Vue][ElementUI] Can I use the variable name to create a component


 There is a NavMenu and a Main component.Once I click the the menu,I want to create a component in the Main component.
 And I don't know what component will be created until it is clicked.

main.vue:
<el-tabs v-model='xxx'>
    <el-tab-pane>[there will be the component]</el-tab-pane>
</el-tabs>

 What should I do ?


Solution

  • Can I use the variable name to create a component?

    Yes, it's called Dynamic Components

    Learn more Dynamic Components here

    You can use attribute is to create a dynamic component.

    Learn more :it here

    <component v-bind:is="currentTabComponent"></component>