[Vue @Component] Dynamic Vue.js components with the component element

Source: Internet
Author: User

You can dynamically switch between-a template by using the reserved <component> element and dynamically bind to it S is attribute. By using your <keep-alive> can tell Vue to keep the component in memory.

In the previous post about dynamic component

<Component: is= "selectedcomp"></Component><Script>Import Vue from"Vue"Import {Component, Prop} from"Vue-property-decorator"Const One={functional:true, Name:" One", Render:h= <H1 class="bg-red"> One</h1>}const={functional:true, Name:" Both", Render:h= <H1 class="Bg-green"> Both</h1>}const Three={functional:true, Name:"three", Render:h= <H1 class="Bg-purple">three</h1>} @Component ({components : {}}) exportdefaultclass App extends Vue {comps=[One, the other, three] Selectedcomp=  This. comps[0]}</Script>

Because inside @Component ({components: {}}) Haven ' t register those Component ' one, both, three ', so then using

<:is = "Selectedcomp"></component>

' Selectedcomp ' have to Ben a real functional component.

But If we are registered the components:

@Component ({components  : {One     , both, three  }})

The ' Selectedcomp ' can be just component ' s name:

Selectedcomponent = ' One ' | ' Both ' | ' Three '

<keep-alive> Component:

Components might has some state, your want to keep the state instead of losting it, you can use ' keep-alive ' component:

< keep-alive >    <  v-bind:is= "CurrentView"  v-bind:initial-quantity= "Item.quantity" V-bind:name = "Item.text" V-bind:diet = "Item.diet" ></ Component > </ keep-alive >

[Vue @Component] Dynamic Vue.js components with the component element

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.