Vue JS Dynamic component and template loading

Vue JS Dynamic component and template loading

In this Post We Will Explain About is Vue JS Dynamic component and template loading With Example and Demo.Welcome on infinityknow.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to change component template dynamicallyExample

In this post we will show you Best way to implement Vue components with different templates, hear for Dynamic Components in Vuejs Examplewith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

READ :  Laravel 6 get ip address from request

we can use the simple same mount point data and dynamically data switch between single or multiple components as well as template using the reserved element for HTML and dynamically all the data bind to its is attribute:

Syntax of Dynamic component and template using Vue js

javascript syntex
[php]
var vm = new Vue({
el: ‘#example’,
data: {
currentView: ‘home’
},
components: {
home: { /* … some code for web apps */ },
posts: { /* … some code for web apps */ },
archive: { /* … some code for web apps */ }
}
})
[/php]
HTML Part
[php]



[/php]

READ :  C# Multidimensional Arrays Tutorial with Examples

Example 1 : Dynamic component and template loading with VueJS

[php]

var myroute = new VueRouter({hashbang:false})
var droute_Map = {};

myroute.beforeEach( function (transition) {
var livepath = transition.to.livepath;
if ((livepath != ‘/’) && !(livepath in droute_Map)) {
_ajax(‘/reports/’+ livepath + ‘.html’, function(res){// here vuejs $.ajax replacement like as a (async)
droute_Map[livepath] = {
component: {
template: res
}
};
myroute.on(livepath, droute_Map[livepath]); //vue js associate component dynamically loaded simple component

transition.abort(); //abort already current
myroute.stop();
myroute.start(); //restart vuejs myroute
myroute.go(livepath); //create init new simple transition to the default same livepath
});//_ajax
} else
transition.next(); //simple default action for just already loaded content
});

[/php]

Example

I hope you have Got What is How to initialize a template dynamically with the result of an ajax call using Vuejs And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.

READ :  VueJS Grid - Advanced Data Grid Component

Leave a Comment