A Modern, Progressive JavaScript Framework

By the end of this course you will be able to build a real Vue 3 single-page application from an empty folder. You will write components with the Composition API, move data between them deliberately instead of by guesswork, extract repeated logic into composables, wire up a router with dynamic pages and guarded navigation, and keep shared state in a Pinia store that still makes sense after a page reload.

What Vue actually is

Vue is two things that happen to be shipped together.

The first is a reactivity system. You describe state as plain JavaScript values, and when a value changes, the code that read it is re-run automatically. You never write “find every element that shows this counter and update it” by hand.

The second is a template compiler. You describe what the screen should look like, and Vue turns that description into efficient DOM updates. The compiler is what lets you keep the markup, the logic and the styles of a component in one file.

Everything else in Vue - the router, the dev tools, the ecosystem - is built on top of those two parts. That is why the framework is called progressive: you can use it for one dropdown in an existing server-rendered site, or for a full application with routing, state management and thousands of components, and the core ideas do not change.

The reactivity system in one minute

A ref holds a single value and is the workhorse of Vue 3. Reading value inside a reactive context tracks it; writing to value triggers whatever depends on it.

import { ref, effect } from 'vue';

const count = ref(0);

effect(() => {
  // Re-runs whenever count changes, because count.value is read here.
  console.log('count is now', count.value);
});

count.value = 1; // logs "count is now 1"

reactive is the same idea for objects: it returns a proxy that tracks property access.

import { reactive, effect } from 'vue';

const state = reactive({ user: { name: 'Ada' } });

effect(() => {
  console.log(state.user.name);
});

state.user.name = 'Grace'; // re-runs the effect

Two properties of the system are worth memorising because they explain most Vue bugs:

  • Tracking is scoped to the running effect. A value read outside any effect is simply a value; nothing is tracked, and nothing re-runs.
  • Mutations are the trigger, not assignments. Replacing state.user with a new object is a mutation. Calling state.user.rename() is not, unless rename itself reads and writes reactive state.

The component model

A Vue component is a self-contained unit of user interface with its own template, logic and styles. The recommended way to write one is a single-file component: a .vue file with three top-level blocks.

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

const count = ref(0);

function increment() {
  count.value += 1;
}
</script>

<template>
  <button type="button" @click="increment">
    Clicked {{ count }} times
  </button>
</template>

<style scoped>
button {
  color: #42b883;
}
</style>

The scoped keyword rewrites the generated CSS so that it only applies to this component’s elements, which means you can use plain class names without a naming convention.

Components compose by nesting. A parent renders a child and passes data down as props; the child reports back up with events. That direction - props down, events up - is the single most important habit in Vue, and the whole first lesson of this course exists to make it second nature.

One-way data flow, concretely

<!-- ParentView.vue -->
<script setup>
import { ref } from 'vue';
import Counter from './Counter.vue';

const total = ref(0);
</script>

<template>
  <Counter v-model="total" />
  <p>Total across the app: {{ total }}</p>
</template>
<!-- Counter.vue -->
<script setup>
const model = defineModel({ type: Number, default: 0 });
</script>

<template>
  <button type="button" @click="model++">
    Add one (currently {{ model }})
  </button>
</template>

The parent owns total. The child never mutates it; it only requests a change, and the parent decides whether to accept it. When you later find a value that two unrelated parts of the screen must agree on, this is the moment to reach for a shared store instead of threading props through five layers.

The Composition API

Vue 3 offers two styles for writing component logic:

  • the Options API, where logic is grouped into options such as data, computed and methods;
  • the Composition API, where logic is plain functions called inside setup.

The Composition API is the current default for new code. Three reasons matter more than style:

  1. Reuse without inheritance. A function that uses ref, computed and lifecycle hooks can be extracted and shared. Options are tied to this and to a component instance, so sharing them means mixins, which are hard to trace.
  2. Plain JavaScript. Logic lives in ordinary functions, so it can live in ordinary modules, be unit tested with no component wrapper, and be typed precisely.
  3. One mental model. Vue 3 keeps the Options API working, but mixing the two styles in one project is where confusion starts.

This course uses the Composition API throughout.

Setting up your first project

# Scaffold a project with the official Vue tooling.
npm create vue@latest my-first-app

# Choose "TypeScript" and "Vue Router" when prompted,
# then install and start the dev server.
cd my-first-app
npm install
npm run dev

The dev server gives you hot module replacement: when you save a file, the changed component is patched into the running page without a full reload. You will also want the browser extension called Vue.js devtools, which lets you inspect the component tree and the reactive state of any page.

What is in this course

The chapters follow the official learning path, in the order in which the concepts depend on each other.

  1. Component communication - props, events, v-model, defineModel, provide and inject, and why the classic event bus is a trap.
  2. Composables - what a composable is, ref against reactive, extracting reusable logic, lifecycle hooks, and the difference between watch and watchEffect.
  3. Vue Router - route definitions, dynamic and nested routes, navigation guards, lazy loading, and the difference between route params and query parameters.
  4. State management - reactive state patterns, Vuex and Pinia stores, when a global store is actually warranted, and how to persist state across reloads.

Read them in order the first time. Later, when you are chasing a specific problem, use the chapter list as a reference.

When Vue is the right choice

Vue is a good fit when a team wants one language for the whole stack, when the interface has rich interactive state, or when the project has to be maintained by people who arrive at different times and need to become productive quickly. It is also a good fit when you are embedding behaviour into an existing site: you can mount a Vue app into one container and leave the rest of the page alone.

It is a poor fit when you need server-driven pages with almost no interactivity, when the bulk of the work is data analysis or heavy computation in the browser, or when a design system in another framework is a hard requirement.

Practice

Before you continue, decide where each piece of state should live. A checkout screen has: a step indicator, a list of line items, a coupon code typed into a form, and a “last used coupon” value that should survive a reload. For each one, name the mechanism you would use from this course and say why the others are worse.

Vue 3State PlacementComposition APIArchitecture

Approach:

The question is about choosing the narrowest mechanism that works, and then widening only when a real constraint forces it. Every escalation - local state, props and events, a composable, a shared store - costs you indirection, so you want to stay at the lowest level that satisfies the requirement.

Steps:

  1. Step indicator - it changes only when the user advances a step, and only the checkout screen reads it. Keep it in a ref inside the checkout component. No props, no store.
  2. Line items - the list is fetched once and rendered many times, and a child component renders each row. Fetch it in the parent, pass each item down as a prop, and let the row emit a “remove” event. Props down, events up.
  3. Coupon code being typed - it is a property of the input’s own component and nothing else cares about it until submission. Keep it local to that input component and emit it on submit.
  4. Last used coupon - it must survive a reload and it is read from unrelated screens (for example, a banner on the home page). This is the one that genuinely needs a shared, persisted store: a Pinia store whose state is written to localStorage.

Answer:

StateMechanismWhy the others are worse
Step indicatorLocal refA store or props would add indirection for a value with exactly one reader
Line itemsParent ref plus props and eventsA store would leak cart data into every component that imports it
Coupon textLocal ref in the input componentLifting it to the parent would force the parent to re-render on every keystroke
Last used couponPinia store with persistenceLocal state dies with the page; provide and inject cannot survive a reload

Found an issue with this content?

Tell us what could be improved.