Vue Local Components

Vue Tutorial

Vue Local Components

In Vue.js, local components are components that are registered and used only inside a specific parent component.

They help keep your app clean, modular, and well-scoped.


 What are Local Components?

A local component is:

  • Imported into a component

  • Registered inside that component

  • Available only there, not globally

 Scope:

Parent Component
└── Local Component (usable only here)

 Why Use Local Components?

  •  Better encapsulation
  •  Avoids global namespace pollution
  •  Improves maintainability
  •  Ideal for feature-specific UI

 Basic Example

 Child Component (HelloBox.vue)


 


 Parent Component (App.vue)


 

  • HelloBox is local to App.vue only

 Local Registration Syntax

Or with alias:


 Using Multiple Local Components


 Local-Components with Props

  •  Works exactly like global components, but scoped locally

 Local Components with v-for

  •  Very common in real projects

 Local vs Global Components (Important)

FeatureLocalGlobal
ScopeOne componentEntire app
PerformanceBetterSlightly heavier
MaintainabilityHighLower
RecommendedYes Limited use
  •  Use local components by default
  •  Use global components only for base UI (buttons, icons)

 Common Use Cases

  • Feature pages

  • Dashboard widgets

  • Page-specific modals

  • Cards, lists, sections


 Common Mistakes

  •  Forgetting to register component
  •  Using global components unnecessarily
  •  Wrong import path
  •  Name mismatch in template

 Best Practices

  •  Prefer local registration
  •  Use PascalCase component names
  •  Keep components small & focused
  •  Register only what you use
  •  Use global components sparingly

 Summary Table

TaskHow
Import componentimport A from './A.vue'
Register locallycomponents: { A }
Use in template<A />
Limit scopeLocal components
ReusabilityControlled & clean

Conclusion

Local components are the default and recommended way to build Vue applications.
They keep your code organized, scalable, and easy to maintain.

You may also like...