What is Vue.js?
Understanding Vue.js philosophy, reactivity system, and why it's loved by developers
- Course
- Vue fundamentals
- Lesson
- 1 of 9
- Level
- Beginner
- Reading time
- 12 minutes
Introduction to Vue.js ¶
Vue.js is a progressive JavaScript framework for building user interfaces. Unlike monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable.
Learning objectives
- Understand Vue.js core philosophy and design principles
- Learn about Vue's reactivity system
- Compare Vue with other frameworks
- Recognize when Vue is the right choice
Why Vue.js? ¶
- Approachable: builds on standard HTML, CSS and JavaScript with an intuitive API.
- Versatile: an incrementally adoptable ecosystem that scales between a library and a full framework.
- Performant: truly reactive, compiler-optimised rendering with little manual optimisation.
Vue.js Core Concepts ¶
The Vue Instance ¶
Every Vue application starts by creating a new Vue instance:
<script setup>
import { ref } from "vue"
const message = ref("Hello Vue!")
</script>
<template>
<div>
<h1>{{ message }}</h1>
</div>
</template>
<style scoped>
h1 {
color: seagreen;
}
</style>Single-file components (SFC)
.vue files that encapsulate template, logic, and styles in a single file. This is one of Vue's most beloved features!Reactivity System ¶
Vue's reactivity system is at the heart of the framework. It automatically tracks JavaScript state changes and efficiently updates the DOM.
<script setup>
import { ref } from 'vue'
const count = ref(0)
const name = ref('Vue Developer')
function increment() {
count.value++
}
</script>
<template>
<button @click="increment">
Count: {{ count }}
</button>
</template>Vue vs Other Frameworks ¶
| Feature | Vue | React | Angular |
|---|---|---|---|
| Learning curve | Gentle | Moderate | Steep |
| Template syntax | HTML-based | JSX | HTML-based |
| State management | Pinia, Vuex | Redux, Zustand | NgRx, services |
| Bundle size | ~33 KB | ~42 KB | ~130 KB |
| TypeScript | First-class | Good support | Built-in |
When to Use Vue ¶
Quick Start Example ¶
Here's a complete Vue 3 component showcasing the basics:
<script setup lang="ts">
import { ref, computed, onMounted } from "vue"
interface Todo {
id: number
text: string
completed: boolean
}
const todos = ref<Todo[]>([])
const newTodo = ref("")
const completedCount = computed(() => todos.value.filter((t) => t.completed).length)
function addTodo() {
if (newTodo.value.trim()) {
todos.value.push({
id: Date.now(),
text: newTodo.value,
completed: false,
})
newTodo.value = ""
}
}
function toggleTodo(id: number) {
const todo = todos.value.find((t) => t.id === id)
if (todo) todo.completed = !todo.completed
}
onMounted(() => {
console.log("Component mounted!")
})
</script>
<template>
<div class="todo-app">
<h1>Vue Todo App</h1>
<form @submit.prevent="addTodo">
<input v-model="newTodo" placeholder="Add a todo..." />
<button type="submit">Add</button>
</form>
<ul>
<li v-for="todo in todos" :key="todo.id" :class="{ completed: todo.completed }" @click="toggleTodo(todo.id)">
{{ todo.text }}
</li>
</ul>
<p>Completed: {{ completedCount }} / {{ todos.length }}</p>
</div>
</template>
<style scoped>
.completed {
text-decoration: line-through;
opacity: 0.6;
}
</style>Next Steps ¶
Next lesson
Setting up a Vue development environment
Now that you understand what Vue.js is, let's set up your development environment and create your first Vue application!
Further reading