Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 87 ยท Getting Started

Introduction to Vue.js

Meet Vue 3, the progressive JavaScript framework. Learn declarative rendering, how Vue compares to vanilla JavaScript and React, and where Vue is used.

Vue.js (usually just "Vue", pronounced like "view") is a JavaScript framework for building user interfaces. You describe what the page should look like for a given piece of data, and Vue keeps the page in sync whenever that data changes. You stop writing code that says "find this element and change its text" and start writing code that says "this text is the current count".

Vue was created by Evan You and first released in 2014. It is now one of the three most widely used front-end frameworks, next to React and Angular. This tutorial teaches Vue 3, the current major version, from your first template all the way to components, forms, routing concepts, testing and complete projects.

What "progressive framework" means

Vue calls itself a progressive framework. You can adopt it in layers:

  • A script tag on an existing page. Drop Vue into one div of a server-rendered page and make just that widget interactive. No build tools needed.
  • A full single-page application. Use a build tool, single-file components, a router and a store when the project grows.
  • Server-side rendering and beyond. Frameworks such as Nuxt are built on Vue and add file-based routing and server rendering.

You do not have to learn all of that at once. The core of Vue is small: a template language, a reactivity system and components. Everything in this lesson and the next few lessons runs in a single HTML file, which is also how the live examples on this site work.

Declarative rendering

Here is the idea in its smallest form. The first half of this example updates the page by hand with plain JavaScript (the imperative way). The second half does the same thing with Vue (the declarative way).

Imperative DOM updates versus Vue

Press both buttons. They look identical, but notice the difference in the code. The vanilla version has to remember which element shows the count and update it in every place that changes the number. The Vue version has one template that says {{ count }} and one handler that says count++. The link between the data and the screen is Vue's job.

With two buttons that is a small saving. With a table of 200 rows, filters, a shopping cart and a header badge that all depend on the same data, it is the difference between a manageable program and a pile of bugs where one screen forgets to update.

flowchart LR
    S["State<br/>count = 0"] --> T["Template<br/>{{ count }}"]
    T --> D["DOM<br/>what the user sees"]
    D -- "click: count++" --> S

You change the state, Vue re-renders the template, and the DOM is updated. The arrow back from the DOM is a user event that changes the state again.

Reactivity in one example

The thing that makes this work is reactivity: Vue notices which pieces of data a template reads, and re-runs only the affected rendering when one of them changes. You never call a "refresh" function. Let's use it with a list, because lists are where hand-written DOM code hurts most.

A list that follows its data

Click the button a few times. The heading, the list and the warning (which appears once there are more than five tasks) all update, and your code never mentions any of them. You only pushed a string into an array. The pieces you saw are Vue's template directives: v-for repeats an element, v-if shows it conditionally, :key helps Vue track list items and @click listens for events. Each gets its own lesson soon.

Vue compared with vanilla JavaScript and React

Versus vanilla JavaScript. Vanilla JavaScript is perfect for small enhancements and is what Vue is built on, so everything you know about the DOM and events still applies. Once many parts of the page share state, hand-written DOM code becomes hard to keep correct. Vue takes over exactly that bookkeeping.

Versus React. Both are component-based and both keep the page in sync with state. The differences are mostly in style:

Topic Vue React
Markup HTML-like templates with directives (v-if, v-for) JSX: markup written inside JavaScript
Updating state Mutate it: count.value++ Replace it with a setter: setCount(count + 1)
Change detection Tracks which data each template reads, then updates precisely Re-runs the component function, then compares the result
Official extras Router and state library (Pinia) are maintained by the Vue team Mostly left to the community

Neither is "better". If you learn Vue first, React will feel familiar in structure (components, props, events); only the syntax and the way state is updated differ. The lesson Introduction to React gives the other side of this comparison.

Single-page applications

Vue is most often used to build a single-page application (SPA): the server sends one HTML page and one bundle of JavaScript, and from then on the script draws every screen. Clicking a link does not ask the server for a new page; the router swaps the components on screen and the app fetches only the data it needs, usually as JSON.

Advantages

  • Fast, app-like navigation. After the first load, moving between screens costs one small data request instead of a full page download.
  • Less server work and bandwidth. The server returns data, not repeated page chrome (header, sidebar, footer) on every click.
  • Responsive feel. Transitions, optimistic updates and instant form feedback are natural, because the page never reloads.
  • One backend for many clients. The same JSON API can feed the web app, a mobile app and other services.
  • Smooth hand-off to mobile-style UIs. The state of the screen lives in JavaScript, so it survives navigation (a half-filled form, a scroll position, a playing video).

Disadvantages

  • SEO and first paint. Crawlers and slow phones receive an almost empty page until the script runs. Server-side rendering or pre-rendering fixes this (SSR and hydration, Nuxt).
  • A bigger first download. The bundle contains the router, the framework and your code. Code splitting and lazy loading keep it small (build and load performance).
  • Client-side resource use. Long sessions with large state can use a lot of memory, and low-end devices do more of the work.
  • You rebuild what the browser gave for free. Back button behavior, scroll restoration, focus management and page titles must be handled by your router and code (routing concepts, accessibility).
  • More tooling and skills. A build step, a router, a state strategy and an API layer all need choices and a team that knows them.

A site that is mostly articles, with little interaction, may not need an SPA at all. Vue works well for that case too, because it can enhance one part of a normal page (ways to use Vue).

The MVVM idea behind Vue

Vue's design is often described with the Model-View-ViewModel (MVVM) pattern:

  • The Model is your data and business rules: plain objects, API responses, a store.
  • The View is what the user sees: the DOM produced from your template.
  • The ViewModel is the glue. In Vue it is the component instance, with its reactive state and the functions the template calls. It holds exactly the data shape the view needs and reacts when either side changes.

Vue's reactivity system is the binding engine between the ViewModel and the View. When state changes, the DOM updates; with v-model, when the user types, the state updates. That is the two-way binding you will meet in Forms and v-model, as opposed to the one-way data flow used between components, where a parent passes data down through props and the child asks for changes with events (props, emits). Two-way binding is a convenience for form fields; one-way flow keeps data changes traceable in large applications.

Which Vue version?

Vue 2 reached end of life on December 31, 2023, so new work uses Vue 3. This course uses Vue 3.5. Vue 3 offers two ways to write components: the Options API (an object with data, methods and so on) and the Composition API (functions such as ref and computed). The examples here mostly use the Composition API, and a later lesson covers the Options API because you will meet it in older code.

Where Vue is used

Vue is used for dashboards, admin panels, e-commerce front ends, interactive widgets inside server-rendered sites (Laravel projects often use it this way) and large single-page applications. Well-known products such as GitLab have used Vue in their interfaces. Its low entry barrier and gentle learning curve make it popular for teams that have a lot of HTML and CSS skill and want to add interactivity without adopting a whole new language like JSX.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does it mean that Vue is a progressive framework?

    Progressive means incremental adoption. You can enhance one widget on an existing page or build a whole single-page app with the same core ideas.
  2. 2. In the Vue counter example, what do you change to update the number on the screen?

    Declarative rendering means you describe the output for a given state and only change the state. Vue keeps the DOM in sync.
  3. 3. How do you update a counter stored in a ref in Vue, compared with React's useState?

    Vue's reactivity tracks mutations, so count.value++ is enough. React expects you to replace state through the setter function.
  4. 4. Which version of Vue should you learn for new projects?

    Vue 3 is the current version. Vue 2 reached end of life on December 31, 2023.

Summary

  • Vue is a JavaScript framework for building user interfaces; you describe the UI for a given state and Vue keeps the DOM in sync.
  • It is progressive: a script tag is enough to start, and build tools, a router and a store come later when you need them.
  • Reactivity means Vue tracks which data a template reads and updates only what changed.
  • Compared with React, Vue uses HTML-like templates and mutable reactive state; the component ideas are the same.
  • This course teaches Vue 3 with mostly the Composition API.

Next: Your First Vue App