Explain it simply
Component Basics, in plain language
A Vue component can have <script setup>, <template>, and an optional <style scoped>. Split components into small pieces, each with one feature or responsibility. Once a component is imported in <script setup>, you can use it directly in the template.
Problem → Why → Solution
The problem — why this concept matters
Cramming every feature into a single component
A common mistake
Using a component's tag in an SFC without importing it
Core concept — understand how it works
Split the UI into separate, reusable pieces using Single-File Components.
- props or event
- component and template
- rendered Vue UI
Understand the structure of a Vue SFC
Core syntax or pattern
<!-- CounterButton.vue -->
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
<template>
<button @click="count++">Clicked {{ count }} times</button>
</template>
<style scoped>
button { padding: .75rem 1rem; }
</style>Split the UI into separate, reusable pieces using Single-File Components.
Read the code step by step
- props or event
<!-- CounterButton.vue -->A Vue component can have <script setup>, <template>, and an optional <style scoped>. Split components into small pieces, each with one feature or responsibility. Once a component is imported in <script setup>, you can use it directly in the template.
- component and template
<template>Split the UI into separate, reusable pieces using Single-File Components.
- rendered Vue UI
</style>Apply Component Basics in a small example and test normal, edge, and failure cases.
- props or event
- component and template
- rendered Vue UI
Success
Understand the structure of a Vue SFC
Failure
Cramming every feature into a single component
Let's break it down simply
A Vue component can have <script setup>, <template>, and an optional <style scoped>. Split components into small pieces, each with one feature or responsibility. Once a component is imported in <script setup>, you can use it directly in the template.
<!-- CounterButton.vue -->
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
<template>
<button @click="count++">Clicked {{ count }} times</button>
</template>
<style scoped>
button { padding: .75rem 1rem; }
</style>Clicked 0 timesTry it yourself
Create an AvatarCard.vue component and reuse it three times inside App.vue.
Components Basics — Vue.js
Real-world usage
How to apply it in a real project
Apply Component Basics in a small example and test normal, edge, and failure cases.
Mini challenge
Build it yourself
Create an AvatarCard.vue component and reuse it three times inside App.vue.
- Rebuild the example without copying it
- Test a normal input and an edge case
- Predict the compiler or output result before running it
<!-- CounterButton.vue -->
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
<template>
<button @click="count++">Clicked {{ count }} times</button>
</template>
<style scoped>
button { padding: .75rem 1rem; }
</style>Expected: Understand the structure of a Vue SFC
Show hint
Apply Component Basics in a small example and test normal, edge, and failure cases.
Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- props or event → component and template → rendered Vue UI
- Split the UI into separate, reusable pieces using Single-File Components.
- Cramming every feature into a single component
- Apply Component Basics in a small example and test normal, edge, and failure cases.
Components Basics — Vue.js