TExcelTAD
Home › Vue › Vue Intro

Vue Introduction

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 no longer write code like element.textContent = … by hand — Vue does it for you.

Vue calls itself a progressive framework: you can sprinkle it into a single widget on an existing page, or build a complete single-page application with routing, state management and a build step. The same core ideas work at every size.

What is Vue used for?

  • Interactive widgets inside server-rendered pages (a search box, a cart, a booking form)
  • Full single-page applications (dashboards, admin panels, web shops)
  • Desktop and mobile apps through tools such as Electron, Capacitor or Ionic
  • Static sites and server-rendered apps with frameworks built on Vue, such as Nuxt and VitePress

Why learn Vue?

Feature What it means for you
Declarative templates Write HTML-like markup with {{ }} placeholders; Vue fills in the values
Reactivity Change a variable and every place that uses it updates automatically
Components Split the UI into small, reusable pieces with their own data and logic
Gentle learning curve If you know HTML, CSS and a bit of JavaScript, you can start today
Great tooling Vite, Vue DevTools, Vue Router, Pinia and Vitest all come from the same ecosystem

Your first Vue app

Every Vue app has three parts: an HTML element to control (here <div id="app">), a template inside it, and a JavaScript object that holds the data. Press ▶ Run, then edit the message and run it again.

html · try it yourself
<div id="app">
  <h1>{{ message }}</h1>
  <p>Vue version: {{ version }}</p>
</div>

<script type="module">
  import { createApp, version } from 'vue';

  createApp({
    data() {
      return { message: 'Hello, Vue!', version };
    }
  }).mount('#app');
</script>

createApp(...) creates an application from an options object, and .mount('#app') tells Vue which element to take over. The double curly braces {{ message }} are called text interpolation: Vue replaces them with the current value of message.

Tip: In every playground on ExcelTAD you can edit the code and press Ctrl+Enter to run it.

Reactivity in action

The real power shows up when data changes. In the next example a button increases a counter. Notice that there is no code that touches the DOM — we only change count, and Vue re-renders the parts of the page that depend on it.

html · try it yourself
<div id="app">
  <p>You clicked {{ count }} times.</p>
  <button @click="count++">Click me</button>
  <p v-if="count >= 5">🎉 That's a lot of clicks!</p>
</div>

<script type="module">
  import { createApp } from 'vue';

  createApp({
    data() {
      return { count: 0 };
    }
  }).mount('#app');
</script>

@click attaches a click listener and v-if shows an element only when a condition is true. Both are directives — special attributes that you will meet in the next lessons.

Two ways to write a component: Options API and Composition API

Vue offers two styles for organising component code:

Style How it looks Good for
Options API An object with data, methods, computed, watch… Beginners, small widgets, code that reads like a form
Composition API A setup() function using ref, computed, watch… Larger apps, sharing logic between components, TypeScript

Here is the same counter written with the Composition API. ref(0) creates a reactive value; everything returned from setup() is available in the template.

html · try it yourself
<div id="app">
  <p>{{ name }} has {{ count }} apples.</p>
  <button @click="count--">Eat one</button>
  <button @click="count++">Buy one</button>
</div>

<script type="module">
  import { createApp, ref } from 'vue';

  createApp({
    setup() {
      const name = ref('Linh');
      const count = ref(3);
      return { name, count };
    }
  }).mount('#app');
</script>

Both styles are fully supported in Vue 3 and you can mix them in one project. This course starts with the Options API because it is easy to read, then teaches the Composition API in its own section.

How Vue works, in short

  1. Vue reads the template (the HTML inside #app) and compiles it into a render function.
  2. The render function produces a lightweight description of the page, the virtual DOM.
  3. While rendering, Vue records which data each part of the page used.
  4. When that data changes, Vue re-runs only the affected render work and patches the real DOM with the minimum changes.

Note: The examples on this site load Vue as an ES module through an import map, so import { createApp } from 'vue' works without any build step. In the Get Started lesson you will see how to create a real project with Vite.

Test yourself

What does {{ message }} do in a Vue template?

  1. Creates a comment
  2. Inserts the current value of message as text
  3. Declares a new variable
  4. Imports a module

Which call attaches a Vue app to the element <div id="app">?

  1. app.render('#app')
  2. app.attach('#app')
  3. app.mount('#app')
  4. new Vue('#app')

What does 'reactive' mean in Vue?

  1. The page updates automatically when the data it uses changes
  2. The app reloads the page on every click
  3. Components are written in React
  4. The CSS animates by itself