Skip to content

Vue.js Tutorial

Official Documentation

This tutorial is based on the official Vue.js documentation. For the most up-to-date information, visit: https://vuejs.org/

Welcome to the Vue.js tutorial! Learn how to build modern, reactive web applications with the progressive JavaScript framework. This tutorial covers both JavaScript and TypeScript using the Composition API.

What is Vue.js?

Vue.js is a progressive JavaScript framework for building user interfaces. It's designed to be incrementally adoptable and focuses on the view layer.

┌─────────────────────────────────────────────────────────────┐
│                    Vue.js Key Features                       │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   1. REACTIVE DATA BINDING                                  │
│   ┌─────────────────────────────────────────────────────┐  │
│   │  Data changes → View updates automatically           │  │
│   │                                                      │  │
│   │   Data: { count: 0 }  ──────►  <p>Count: 0</p>      │  │
│   │   Data: { count: 5 }  ──────►  <p>Count: 5</p>      │  │
│   └─────────────────────────────────────────────────────┘  │
│                                                             │
│   2. COMPONENT-BASED                                        │
│   ┌─────────────────────────────────────────────────────┐  │
│   │  Build UIs with reusable, self-contained pieces      │  │
│   │                                                      │  │
│   │   ┌──────┐  ┌──────┐  ┌──────┐                      │  │
│   │   │Header│  │ Card │  │Button│  ← Components        │  │
│   │   └──────┘  └──────┘  └──────┘                      │  │
│   └─────────────────────────────────────────────────────┘  │
│                                                             │
│   3. SINGLE-FILE COMPONENTS (SFC)                          │
│   ┌─────────────────────────────────────────────────────┐  │
│   │  Template + Script + Style in one .vue file          │  │
│   │  Clean, organized, and maintainable code!            │  │
│   └─────────────────────────────────────────────────────┘  │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Options API vs Composition API

Vue 3 offers two ways to write components. This tutorial focuses on the Composition API:

FeatureOptions APIComposition API
StructureObject with data, methods, computedSetup function with reactive refs
Code OrganizationBy option typeBy logical concern
TypeScriptGood supportExcellent support
ReusabilityMixinsComposables
Learning CurveEasier for beginnersMore flexible
RecommendedVue 2 styleVue 3 recommended

Why Composition API?

The Composition API provides better TypeScript support, code reuse through composables, and more flexible code organization. It's the recommended approach for Vue 3.

JavaScript vs TypeScript

This tutorial provides examples in both JavaScript and TypeScript:

FeatureJavaScriptTypeScript
File Extension.vue.vue (with <script lang="ts">)
Type SafetyRuntime errorsCompile-time errors
IDE SupportGoodExcellent
Props ValidationRuntime onlyCompile + Runtime

Why Learn Vue.js?

FeatureDescription
Easy to LearnGentle learning curve, great documentation
ReactiveAutomatic UI updates when data changes
FlexibleUse as much or as little as you need
PerformantVirtual DOM with optimized rendering
Great ToolingVue DevTools, Vite, Vue CLI
Rich EcosystemVue Router, Pinia, Nuxt.js

What You'll Learn

Beginner

Intermediate

Advanced

Prerequisites

Before starting this tutorial, you should know:

  • ✅ HTML & CSS basics
  • ✅ JavaScript fundamentals (ES6+)
  • ✅ Basic understanding of the DOM
  • ⭐ TypeScript basics (optional, for TS examples)

New to JavaScript?

Check out our JavaScript Tutorial first!

Quick Preview

vue
<script setup>
import { ref } from 'vue'

// Reactive state
const count = ref(0)
const name = ref('Vue Developer')

// Methods
function increment() {
  count.value++
}
</script>

<template>
  <div class="app">
    <h1>Hello, {{ name }}!</h1>
    <p>Count: {{ count }}</p>
    <button @click="increment">Click me</button>
  </div>
</template>

<style scoped>
.app {
  text-align: center;
  padding: 20px;
}
button {
  padding: 10px 20px;
  font-size: 16px;
}
</style>
vue
<script setup lang="ts">
import { ref, Ref } from 'vue'

// Typed reactive state
const count: Ref<number> = ref(0)
const name: Ref<string> = ref('Vue Developer')

// Typed methods
function increment(): void {
  count.value++
}
</script>

<template>
  <div class="app">
    <h1>Hello, {{ name }}!</h1>
    <p>Count: {{ count }}</p>
    <button @click="increment">Click me</button>
  </div>
</template>

<style scoped>
.app {
  text-align: center;
  padding: 20px;
}
button {
  padding: 10px 20px;
  font-size: 16px;
}
</style>

Setting Up Your Environment

JavaScript Setup

bash
# Create a new Vue app with Vite (JavaScript)
npm create vue@latest my-vue-app

# When prompted, select:
# ✔ Add TypeScript? No
# ✔ Add JSX Support? No
# ✔ Add Vue Router? No (for now)
# ✔ Add Pinia? No (for now)

cd my-vue-app
npm install
npm run dev

TypeScript Setup

bash
# Create a new Vue app with Vite (TypeScript)
npm create vue@latest my-vue-app

# When prompted, select:
# ✔ Add TypeScript? Yes
# ✔ Add JSX Support? No
# ✔ Add Vue Router? No (for now)
# ✔ Add Pinia? No (for now)

cd my-vue-app
npm install
npm run dev

Your app will be running at http://localhost:5173

Project Structure

my-vue-app/
├── node_modules/
├── public/
│   └── favicon.ico
├── src/
│   ├── assets/           # Static assets
│   ├── components/       # Vue components
│   │   └── HelloWorld.vue
│   ├── App.vue           # Root component
│   └── main.js           # Entry point
├── index.html
├── package.json
└── vite.config.js
my-vue-app/
├── node_modules/
├── public/
│   └── favicon.ico
├── src/
│   ├── assets/           # Static assets
│   ├── components/       # Vue components
│   │   └── HelloWorld.vue
│   ├── App.vue           # Root component
│   ├── main.ts           # Entry point (.ts)
│   └── vite-env.d.ts     # Type declarations
├── index.html
├── package.json
├── tsconfig.json         # TypeScript config
└── vite.config.ts

Single-File Component (SFC) Structure

Every .vue file has three sections:

vue
<!-- 1. SCRIPT - JavaScript/TypeScript logic -->
<script setup>
// Your component logic here
</script>

<!-- 2. TEMPLATE - HTML structure -->
<template>
  <div>Your HTML here</div>
</template>

<!-- 3. STYLE - CSS styling (scoped by default) -->
<style scoped>
/* Your CSS here */
</style>

Video Tutorials

Recommended Video Resources

Learn Vue.js through these excellent video tutorials from the community.

Free Courses

CourseCreatorDescription
Vue 3 Crash CourseTraversy Media1-hour crash course covering Vue 3 fundamentals
Vue.js Course for BeginnersfreeCodeCamp3+ hour comprehensive beginner course
Vue 3 TutorialThe Net NinjaComplete playlist covering Vue 3 basics
Vue 3 Composition APIFireshipQuick 100-second explanation of Vue

Official Resources

ResourceDescription
Vue Mastery (Free Intro)Official recommended course with free intro lessons
Vue School (Free Lessons)Vue 3 Fundamentals course

Topic-Specific Videos

TopicVideoDuration
Composition APIVue 3 Composition API Tutorial~30 min
Vue RouterVue Router 4 Tutorial~20 min
Pinia StatePinia Crash Course~30 min
TypeScript + VueVue 3 + TypeScript~45 min

Let's Begin!

Ready to start building with Vue? Head over to the Getting Started guide!


Get Started →