vuejs
/

Vue Components Introduction

Last Sync: Today

On this page

9
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

vuejs

Vue Components Introduction

What are Components?

Components are reusable, self-contained pieces of UI that help build complex applications in a modular way.

Why Use Components?

  • Reusable UI elements
  • Better code organization
  • Improved maintainability
  • Separation of concerns

Basic Component Example

JavaScriptRead-only
1
const app = Vue.createApp({});

app.component('my-component', {
  template: '<h1>Hello Component</h1>'
});

Using Component

HTMLRead-only
1
<my-component></my-component>

Single File Component (SFC)

HTMLRead-only
1
<template>
  <h1>Hello Vue</h1>
</template>

<script>
export default {
  name: 'MyComponent'
}
</script>

<style>
h1 { color: blue; }
</style>

Component Types

TypeDescription
Global ComponentsAvailable across the app
Local ComponentsUsed within specific components
Single File ComponentsDefined in .vue files

Best Practices

  • Keep components small and reusable
  • Use meaningful component names
  • Organize components in folders
  • Avoid duplicate logic across components

Common Mistakes

  • Creating very large components
  • Not reusing components
  • Poor naming conventions
  • Mixing multiple responsibilities in one component

Conclusion

Vue components are the building blocks of applications. Using them effectively leads to scalable and maintainable code.

Try it yourself

app.component('my-component', { template: '<h1>Hello</h1>' });

Test Your Knowledge

Q1
of 3

Components are?

A
Database
B
Reusable UI
C
API
D
Server
Q2
of 3

SFC stands for?

A
Simple File Code
B
Single File Component
C
Static File Component
D
System File Code
Q3
of 3

Component helps?

A
Complexity
B
Reusability
C
Errors
D
Database

Frequently Asked Questions

What is a Vue component?

A reusable UI block in Vue.

What is SFC?

Single File Component with template, script, and style.

Why use components?

To build modular and maintainable apps.

Previous

vue custom directives

Next

vue props

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.