Vue Local Components

Vue Local Components
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:
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)
HelloBoxis local toApp.vueonly
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)
| Feature | Local | Global |
|---|---|---|
| Scope | One component | Entire app |
| Performance | Better | Slightly heavier |
| Maintainability | High | Lower |
| Recommended | Yes | 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
| Task | How |
|---|---|
| Import component | import A from './A.vue' |
| Register locally | components: { A } |
| Use in template | <A /> |
| Limit scope | Local components |
| Reusability | Controlled & clean |
Conclusion
Local components are the default and recommended way to build Vue applications.
They keep your code organized, scalable, and easy to maintain.
