TExcelTAD
Home › Vue › Vue Get Started

Vue Get Started

There are two common ways to start using Vue:

Approach Setup Best for
CDN / ES module Add one <script> to an HTML file Learning, prototypes, adding a widget to an existing page
Vite project (npm create vue@latest) Node.js + a build step Real applications with components in .vue files, routing, tests

Both use exactly the same Vue — the difference is only in how the code reaches the browser.

Option 1: Vue from a CDN (global build)

The quickest start is a single HTML file. The global build puts everything on a Vue variable:

html
<!DOCTYPE html>
<html>
<body>
  <div id="app">{{ greeting }}</div>

  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    createApp({
      data() { return { greeting: 'Hi from a CDN!' }; }
    }).mount('#app');
  </script>
</body>
</html>

Save this as index.html, open it in a browser, and it works — no installation needed.

Option 2: Vue as an ES module

Modern browsers understand import. With an import map you can write import ... from 'vue' exactly as you would in a real project. This is how every playground on ExcelTAD loads Vue:

html
<script type="importmap">
  { "imports": { "vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js" } }
</script>
<div id="app">{{ greeting }}</div>
<script type="module">
  import { createApp } from 'vue';
  createApp({ data: () => ({ greeting: 'Hi from an ES module!' }) }).mount('#app');
</script>

On this site the import map is added for you, so a playground only needs the module script:

html · try it yourself
<div id="app">
  <h2>{{ title }}</h2>
  <p>Today we are learning <strong>{{ topic }}</strong>.</p>
</div>

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

  createApp({
    data() {
      return { title: 'Getting started', topic: 'Vue 3' };
    }
  }).mount('#app');
</script>

Note: Builds whose name contains esm-browser or global include the template compiler, so Vue can compile templates written directly in the HTML. Projects built with Vite compile templates ahead of time and ship a smaller runtime-only build.

Option 3: Create a project with Vite

For a real application, use the official scaffolding tool create-vue, which sets up a Vite project. You need Node.js 18.3 or newer. Run this in a terminal and answer the questions:

bash · try it yourself
npm create vue@latest
> npx
> create-vue

┌  Vue.js - The Progressive JavaScript Framework
│
◇  Project name (target directory):
│  my-vue-app
│
◇  Select features to include in your project:
│  Router (SPA development), Pinia (state management), Vitest (unit testing)
│
◇  Select experimental features to include in your project:
│  none
│
◇  Skip all example code and start with a blank Vue project?
│  No

Scaffolding project in /home/me/my-vue-app...
│
└  Done. Now run:

   cd my-vue-app
   npm install
   npm run dev

Then install the dependencies and start the development server:

bash · try it yourself
cd my-vue-app
npm install
npm run dev
added 152 packages, and audited 153 packages in 9s

found 0 vulnerabilities

> my-vue-app@0.0.0 dev
> vite


  VITE v6.3.5  ready in 412 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help

Open http://localhost:5173/ and you will see the starter page. Edit a file and save — the browser updates instantly thanks to Vite's hot module replacement.

What is inside the project?

text
my-vue-app/
├── index.html          the single HTML page; loads /src/main.js
├── package.json        scripts: dev, build, preview, test:unit
├── vite.config.js      Vite configuration with the Vue plugin
├── public/             static files copied as-is
└── src/
    ├── main.js         createApp(App).mount('#app')
    ├── App.vue         the root component
    ├── components/     your reusable components
    ├── router/         routes (if Router was selected)
    └── stores/         Pinia stores (if Pinia was selected)

src/main.js is the same createApp(...).mount('#app') you already know — but it imports the root component from a Single-File Component (.vue file), which keeps template, script and styles together:

vue
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>

<template>
  <button @click="count++">Count is {{ count }}</button>
</template>

<style scoped>
button { font-weight: bold; }
</style>

You will learn SFCs and <script setup> in the Composition API section. Until then, all examples are runnable HTML playgrounds.

Useful npm scripts

Command What it does
npm run dev Starts the dev server with hot reload
npm run build Builds optimised files into dist/
npm run preview Serves the dist/ folder locally to test the build
npm run test:unit Runs the Vitest tests (if selected)

Tip: Install the Vue DevTools browser extension. It lets you inspect components, their data and events while the app runs.

One more playground: mount two apps

A page can contain several independent Vue apps — handy when adding Vue to an existing site.

html · try it yourself
<div id="header">{{ siteName }}</div>
<hr>
<div id="cart">Items in cart: {{ items }} <button @click="items++">Add</button></div>

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

  createApp({ data: () => ({ siteName: 'TAD Market' }) }).mount('#header');
  createApp({ data: () => ({ items: 0 }) }).mount('#cart');
</script>

Test yourself

Which command scaffolds a new Vue project with the official tool?

  1. npm install vue-cli
  2. npm create vue@latest
  3. vue new project
  4. npx create-react-app

Which file extension is used for Single-File Components?

  1. .vjs
  2. .html
  3. .vue
  4. .sfc

What does npm run build produce in a Vite project?

  1. Optimised static files in dist/
  2. A running dev server
  3. A new component
  4. A Node.js server