35 Mins

1. Introduction to Vue.js & Setup

Introduction to Vue.js

Welcome to the world of Vue.js 3. Vue is a progressive, approachable, and versatile JavaScript framework for building user interfaces. Unlike monolithic frameworks that force you into a specific architecture, Vue is designed to be incrementally adoptable. You can start by using it as a simple script tag to add interactivity to a legacy page, or you can go all-in with a full-stack Single-File Component (SFC) architecture.

At the core of Vue.js 3 is its reactivity system, which utilizes JavaScript Proxy objects. When you define data, Vue wraps it in a reactive proxy. This means that whenever your data changes, Vue automatically tracks those changes and updates the DOM (Document Object Model) efficiently. This is known as a virtual DOM system, which calculates the difference between your state and the current UI, patching only the necessary elements rather than re-rendering the entire page. This approach solves the performance bottlenecks associated with direct DOM manipulation, making it an essential tool for modern web development.

Developer Note: Vue 3's Composition API is the modern standard for writing logic. It allows you to organize your code by feature rather than by options (data, methods, mounted), which significantly improves code maintainability in large-scale applications.

As you progress, you will learn to use ref and reactive, which are the primary primitives for managing component state. Understanding these is the difference between writing static HTML and dynamic, application-grade interfaces. We will focus on the SFC pattern, which packages HTML, CSS, and logic into a single .vue file, enforcing a clean separation of concerns within your components.

Vue 3
<!-- Simple Vue App Setup -->
<div id="app">{{ message }}</div>

<script type="module">
import { createApp, ref } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'

createApp({
  setup() {
    const message = ref('Hello Vue 3!')
    return { message }
  }
}).mount('#app')
</script>

Vue vs Other Frameworks

When choosing a framework, developers often weigh the pros and cons of React, Angular, and Vue. Vue sits in a unique "sweet spot," offering a gentler learning curve than Angular and a more opinionated, out-of-the-box structure than React. While React relies heavily on JSX and manual optimization (like useMemo and useCallback), Vue handles these optimizations automatically through its reactivity compiler.

FeatureDescription
ReactivityVue uses mutable proxies; React uses immutable state and re-renders.
SyntaxVue uses HTML-based templates; React prefers JSX/TSX.
EcosystemVue provides official state management (Pinia) and routing (Vue Router).

This comparison highlights why Vue is often the choice for teams that value developer experience (DX). By providing official libraries for the most common needs—routing and state management—Vue removes the "choice paralysis" often found in the React ecosystem. You are not just learning a library; you are learning an integrated, cohesive framework designed to work together seamlessly from day one.

Vue 3
<script setup>
import { ref, computed } from 'vue';

const count = ref(0);
// Vue automatically tracks 'count.value' dependency. 
// No manual dependency array needed!
const doubleCount = computed(() => count.value * 2);
</script>

Setting Up a Vue Project

To begin, we use create-vue, the official project scaffolding tool. This setup process ensures you have a modern build pipeline powered by Vite, which is an extremely fast build tool that uses native ES modules during development. Start by opening your terminal and running the following command:

Bash
npm create vue@latest

During the setup, you will be presented with a series of prompts. For this course, select the following:

  • Project name: voidx-first-app
  • TypeScript: No
  • Vue Router: Yes
  • Pinia: Yes
  • ESLint: Yes

After the installation completes, you will have a directory structure like the one shown below:

Text
voidx-first-app/
├── node_modules/
├── src/
│   ├── assets/
│   ├── components/
│   ├── router/
│   ├── stores/
│   ├── App.vue
│   └── main.js
├── package.json
└── vite.config.js

The package.json file contains your dependencies, while main.js serves as the entry point that mounts the Vue app instance to your index.html file. Vite manages the hot-module replacement, meaning that every time you save a file, your browser updates in milliseconds without losing application state.

Your First Vue Component

A Vue SFC (Single-File Component) follows the