8 Apr 2021

Vue Component Registration Global & Local Scope


Hi guys, How are you?

Today we will try know that How we can create component in Vue js Globally & Local.

To create a component in Vue is very easy. It can be exported from & import to any other Vuejs project. You can find lots of Vuejs component on GitHub.

Global Scope Components

A component that is registered with Vue.component() static method of Vue Object. And any Vue instance can use it. For better understanding take an example javascript variables. A variable which is create outside of a javascript function is called Variable with Global Scope.

Vue.component("componet-name", {
template : /*    */
});

Local Scope Components

Vue local componet are available to a Vue instance in which the componet are defined. Defined componets are pass through Vue instance as object value `components`. see it in below Example.

const componet1 = {
//defining the template for Vue UI Component

template : "<div> Hello, I am Vue Component </div>"
};
const componet2 = {
template : "... "
}; 

var vm = new Vue({

componets : {
     'component-a'  : componet1,
     'component-b' : componet2
   } 
});



Reaction:

No comments:

No Comments

COMMENT FROM MESSAGE