Web Technologies 2026 · BiUH · Lesson 6

Vue · Getting Started

Node and npm · a new project · the folder · your first components · pages · build and ship

webtech.landrock.io

Eight steps, in order · don't skip one

Today's route.

1Install Node.jsthe engine every tool runs on
2Create a projectone command, a few questions
3Start ita dev server on your own laptop
4Find your way aroundwhich file does what
5Read a .vue filescript, template, style
6PagesVue Router, one header for all
7Your quotes, in Vuea component, a list, a search
8Build and shipfrom .vue files to a live address

Vue calls itself "the progressive framework" — this is what that means

Two ways in.

Five minutes

A · One script tag

Add Vue to one page you already have. No install, no build.

Good for one interactive piece on a normal site.

The rest of the day

B · A real project

Node, Vite, .vue files, a build. What everyone uses for real work.

Components in files, pages, instant reload.

A first, because it shows Vue with nothing in the way. Then B, step by step.

Way A · paste this into any page of my-site

<div id="likes">
  <button @click="likes++">♥ {{ likes }}</button>
</div>

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
  const { createApp, ref } = Vue

  createApp({
    setup() {
      const likes = ref(0)
      return { likes }
    }
  }).mount('#likes')
</script>

Vue takes over only #likes. The rest of your page is untouched.

unpkg slow or blocked? cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js is the same file.

Step 1 · install Node.js

Once per laptop.

  1. Go to nodejs.org and download the version marked LTS
  2. Run the installer. Accept every default — on Windows too.
  3. Close VS Code completely and open it again.
  4. Open the terminal: Ctrl+` — the key above Tab

LTS means "long-term support" — the boring, stable one. Always pick it.

Why restart? A terminal reads the list of installed programs when it opens. One opened before the install has never heard of Node.

Step 1 · check it worked

node -v
npm -v
v24.x.x
11.x.x

Vue needs Node 22.18+ or 24.12+. The npm number can be anything. Older? Install the LTS again.

"command not found" or "not recognized": the terminal was open before the install — restart VS Code. "EBADENGINE" later on: your Node is too old.

Windows only · the most common red error of the day

"running scripts is disabled on this system"

VS Code's terminal on Windows is PowerShell, and PowerShell blocks npm by default. Allow it — once, for your user only:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

Answer Y, then close the terminal and open a new one. npm -v now works.

This allows scripts you installed yourself. Scripts downloaded from the internet still need a signature.

Step 1 · what you just installed

Four words you will hear all day.

nodeJavaScript outside the browser.It runs every tool you use today.
npmThe package manager.Downloads code other people wrote — an app store for code.
package.jsonYour project's shopping list.Which packages, and which commands it knows.
node_modulesThe warehouse.Everything npm downloaded. Big. Never edit it, never commit it.

In China · only if npm is slow

Point npm at a mirror.

npm downloads from a registry in the US. npmmirror keeps a full copy in China.

npm config set registry https://registry.npmmirror.com
npm config get registry

The second line checks it. Same packages, a closer server — a setting on your laptop, not in your project.

npmmirror used to be called the Taobao mirror. Older tutorials still say so — that address no longer works.

Step 2 · create the project

Where you are matters.

Open a terminal in the folder that contains my-site — not inside it. The Vue project is a new project, next to your old one, with its own repository.

npm create vue@latest

It downloads create-vue, the official starter, and asks you some questions.

Asked "Ok to proceed? (y)" — type y. It is asking permission to download create-vue.

Step 2 · the questions · arrows to move, Space to tick, Enter to confirm

No TypeScript. Router only. Blank project.

◇  Project name (target directory):
│  my-vue-site
│
◇  Use TypeScript?
│  No                            ← the default is Yes. Don't just press Enter.
│
◇  Select features to include in your project:
│  Router (SPA development)      ← tick only this one
│
◇  Select experimental features to include in your project:
│  none                          ← just press Enter
│
◇  Skip all example code and start with a blank Vue project?
│  Yes

Pinia, Vitest, Linter, Prettier: leave them unticked — add them when a project needs them. A different create-vue version may word this differently; the three rules stay the same.

Step 3 · install and start

cd my-vue-site
npm install
npm run dev
  VITE v8.x.x  ready in 390 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  Vue DevTools: Open http://localhost:5173/__devtools__/ as a separate window
  ➜  Vue DevTools: Press Alt+Shift+D in App to toggle the Vue DevTools

Ctrl-click the Local address. Your Vue app is running.

Leave this terminal running all day — Ctrl+C stops it. Open a second terminal (the + in the terminal panel) for Git.

Step 3 · what just happened

Three commands, three jobs.

cd my-vue-sitego into the new folder
npm installread package.json, download everything on it into node_modules — Vue, Vite, the router, and what they need: about 175 packages
npm run devstart Vite: a small server on your laptop that translates .vue files the moment the browser asks for them

Change a file and save: the page updates without reloading — and keeps what you typed in it.

It is Live Server, grown up. And like Live Server, it is http://, not file:// — opening index.html by double-click gives you a blank page.

Step 3 · two tools you want before writing any code

In VS Code

Extensions → search Vue (Official) → Install.

Without it, a .vue file is grey text with no help and no errors.

In the browser

Vue DevTools — see every component and its data, live.

create-vue already put it inside your page: the small Vue logo at the bottom, or Alt+Shift+D (Mac ⌥⇧D).

VS Code may offer the extension by itself when you open the folder — "install recommended extensions?" Say yes.

Back to the frameworks deck for one minute

View source on localhost:5173.

<body>
  <div id="app"></div>
  <script type="module" src="/src/main.js"></script>
</body>

An empty div. Now open Inspect → Elements: it is full.

This is a client-rendered app.

Everything you see was built in the browser, by JavaScript, after the page arrived. (In dev, Vite adds a script of its own in the head — ignore it.)

Step 4 · find your way around

Which file does what.

index.htmlthe only HTML page — with the empty <div id="app">
src/main.jsstarts Vue and puts the app into #app
src/App.vuethe root component — the frame around every page
src/components/reusable pieces: a quote card, a button
src/views/one component per page
src/router/index.jswhich URL shows which view
public/copied as-is: favicon, images, your OG image
package.jsonthe shopping list, and the commands dev, build, preview
node_modules/downloaded packages — never edit, never commit

You will work in src/ almost all the time. Missing a folder? Create it.

Step 4 · how the app starts

Find an element. Fill it.

<body>
  <div id="app"></div>
  <script type="module"
          src="/src/main.js"></script>
</body>
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

const app = createApp(App)
app.use(router)
app.mount('#app')

Your nav.js from lesson 4 did exactly this: getElementById('site-header'), then innerHTML. Vue does it for the whole page.

Step 4 · bring the stylesheet you already have

Your CSS still works.

  1. Copy style.css from my-site into src/assets/ — create the folder
  2. Import it once, at the top of src/main.js:
import './assets/style.css'
For the whole sitea CSS file, imported in main.js
For one component<style scoped> inside that .vue file

Got the example project? Delete its line import './assets/main.css' — that file has the demo's two-column layout, and it will fight yours.

Step 5 · one component, one file, three parts

Anatomy of a .vue file.

<script setup>
// JavaScript: the data and the logic
import { ref } from 'vue'
const name = ref('Wuxi')
</script>

<template>
  <!-- HTML: what to show -->
  <h2>Hello from {{ name }}</h2>
</template>

<style scoped>
/* CSS: only for this component */
h2 { color: #2f855a; }
</style>

script setup — what the component knows

template — what it shows

style scoped — how it looks, without leaking onto the rest of the page

HTML, CSS and JavaScript — the three things you already know, together in one file because they belong to one piece of the page.

Step 5 · the template, on one slide

Six things that are not plain HTML.

You writeIt means
{{ likes }}show this value as text
:href="link"set an attribute from data — short for v-bind:href
@click="likes++"run this when the event happens — short for v-on:click
v-if="shown" · v-elseonly put this on the page if true
v-for="q in quotes" :key="q.id"repeat this element for every item
v-model="search"an input and a value, kept in sync both ways

Everything else in a template is HTML. Your semantic markup from lesson 3 goes in unchanged.

Step 5 · only if you got the example project

Clear the demo out first.

  1. Replace src/App.vue with the one in step 6 — or just a <RouterView /> for now
  2. Replace src/views/HomeView.vue with a heading and a paragraph
  3. Then delete everything in src/components/
  4. Delete import './assets/main.css' from src/main.js

In that order — delete a component while a file still imports it and Vite shows a red error until you fix the import.

Chose "blank project"? Skip this slide.

Step 6 · first, three small pages · create src/views/

<template>
  <h1>My quote collection</h1>
  <p>Sentences I keep coming back to.</p>
</template>
<template>
  <h1>About</h1>
  <p>Who collected these, and why.</p>
</template>
<template>
  <h1>Quotes</h1>
  <p>Coming in step 7.</p>
</template>

A component with only a template is fine. Add a script when it needs data.

The quotes page is a placeholder for now. Step 7 fills it.

Step 6 · then the router · which URL shows which page

import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import QuotesView from '../views/QuotesView.vue'
import AboutView from '../views/AboutView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', component: HomeView },
    { path: '/quotes', component: QuotesView },
    { path: '/about', component: AboutView },
  ],
})

export default router

A fourth page: one new file in src/views, one import, one line in routes.

Step 6 · the frame around every page

<script setup>
import { RouterLink, RouterView } from 'vue-router'
</script>

<template>
  <header>
    <nav>
      <RouterLink to="/">Home</RouterLink>
      <RouterLink to="/quotes">Quotes</RouterLink>
      <RouterLink to="/about">About</RouterLink>
    </nav>
  </header>

  <main>
    <RouterView />
  </main>

  <footer>
    <p>© 2026 Your Name</p>
  </footer>
</template>

RouterLink — a link that does not reload the page

RouterView — the hole where the current page goes

Header and footer, written once. Lesson 4's nav.html — without the fetch.

Now click between the three pages. The current one's link gets the class router-link-exact-active — style it.

Step 6 · server and client, live

Open the Network tab. Click "Quotes".

The URL changes to /quotes. But no new HTML page is downloaded — nothing of type "document" appears.

The server was never asked.

The router, in the browser, swapped QuotesView into RouterView. This is client-side routing.

Compare my-site: every link click is a new request, and a new document in the Network tab.

Step 6 · the catch — and it will happen to you after deploying

Reload on /quotes → 404.

Live, open yoursite.com/quotes directly. Many hosts answer 404 Not Found.

The server looks for a file called quotes. There is only index.html. The router lives in the browser — the server has never heard of /quotes.

Fix 1 · tell the host"send index.html for every path" — usually a setting called SPA, fallback or rewrite
Fix 2 · use the #createWebHashHistory() → yoursite.com/#/quotes — works on every host

Why Fix 2 works: the part after # never reaches the server. You learned that in lesson 1, on the URL slide.

Step 7 · the main exercise

Your quote collection —
rebuilt in Vue.

Data in one file. One component for one quote. A list. A search.
Same semantic markup as lesson 3.

Step 7 · first the data, on its own

export const quotes = [
  {
    id: 1,
    text: 'The best time to plant a tree was twenty years ago. The second best time is now.',
    author: 'Chinese proverb',
    source: 'traditional',
  },
  {
    id: 2,
    text: 'Learning without thought is labour lost; thought without learning is perilous.',
    author: 'Confucius',
    source: 'Analects 2.15',
  },
  {
    id: 3,
    text: 'Talk is cheap. Show me the code.',
    author: 'Linus Torvalds',
    source: 'Linux kernel mailing list, 2000',
  },
]

Then replace these three with your own twenty. The data now lives apart from the HTML.

Step 7 · one quote = one component

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

defineProps({
  text: String,
  author: String,
  source: String,
})

const likes = ref(0)
</script>

<template>
  <article class="quote">
    <blockquote>
      <p>{{ text }}</p>
    </blockquote>
    <footer>
      <cite>{{ author }}</cite>, <span class="source">{{ source }}</span>
    </footer>
    <button @click="likes++">♥ {{ likes }}</button>
  </article>
</template>

defineProps — the three values this card is given

likes — a value the card owns

The template is your lesson 3 markup, with {{ }} where the text was.

Your site-wide CSS for .quote, blockquote and cite still applies. Card-only CSS goes in <style scoped>.

Step 7 · twenty quotes, one component · replaces the placeholder

<script setup>
import QuoteCard from '../components/QuoteCard.vue'
import { quotes } from '../data/quotes.js'
</script>

<template>
  <h1>Quotes</h1>
  <QuoteCard
    v-for="q in quotes"
    :key="q.id"
    :text="q.text"
    :author="q.author"
    :source="q.source"
  />
</template>

A new quote is one more item in quotes.js. No HTML to copy.

:text="q.text" hands this quote's text to the card. :key tells Vue which card is which.

Step 7 · two kinds of data

Props and state.

Props · given

Passed in from outside, by the parent.

Read-only inside the component.

Like the attributes of an HTML tag: <img src alt>

State · owned

Made inside the component with ref().

Changes over time — and the screen follows.

Each card has its own likes. Click one: only that one changes.

Reload the page and the likes are back to zero. State lives in the browser's memory — saving it needs localStorage, or a server.

Step 7 · the payoff · replace QuotesView.vue with this

<script setup>
import { ref, computed } from 'vue'
import QuoteCard from '../components/QuoteCard.vue'
import { quotes } from '../data/quotes.js'

const search = ref('')

const shown = computed(() => {
  const s = search.value.toLowerCase()
  return quotes.filter(q => (q.text + ' ' + q.author).toLowerCase().includes(s))
})
</script>

<template>
  <h1>Quotes</h1>
  <label>Search <input v-model="search"></label>
  <p>{{ shown.length }} of {{ quotes.length }}</p>
  <QuoteCard v-for="q in shown" :key="q.id"
    :text="q.text" :author="q.author" :source="q.source" />
</template>

Type in the box: the list and the count follow every key. In the script it is search.value; in the template just search.

Stop and look at what you did not write

No addEventListener.
No innerHTML.
No getElementById.

You described the result for any search text. Vue worked out what to change.

Try the same search and count in plain JavaScript tonight — then count the lines. That is the argument for a framework.

Step 8 · build

npm run build
npm run preview
dist/
├── index.html
├── favicon.ico                  ← everything from public/
└── assets/
    ├── index-B8xK2fQa.js        ← your components + Vue, in one file
    └── index-D4mPq1Lr.css       ← all your CSS

dist/ is a plain static site. No Vue to install, no Node on the server — just files.

The quotes app: about 90 KB of JavaScript, mostly Vue itself. preview serves dist/ on localhost:4173 — exactly what your visitors will get.

Step 8 · what goes into Git

Commit the recipe, not the meal.

FileCommit?
src/ · public/ · index.htmlYes — your work
package.json · vite.config.jsYes — how to build it
package-lock.jsonYes — the exact versions you tested
node_modules/ · dist/Never — anyone can rebuild them

create-vue already wrote a .gitignore that leaves out node_modules and dist.

Step 8 · commit and push

git init
git add .
git commit -m "Start the Vue version of my quote collection"

Then Publish Branch in VS Code, exactly as in the Git deck — a new, public repository.

Before you commit: does Source Control list node_modules or dist? Then something is wrong with .gitignore — stop and ask.

Step 8 · connect your host

Four settings.

Framework presetVite (or Vue)
Build commandnpm run build
Output directorydist
Node.js version22 or newer

Most hosts fill these in when they see Vite. Then every push builds and publishes.

The host runs npm run build on its own machine — build time moves from your laptop to the host.

Read the message, then find it here

When it goes wrong.

You seeIt means
npm not found / not recognizedterminal opened before Node was installed — restart VS Code
running scripts is disabledWindows PowerShell — the Set-ExecutionPolicy slide
npm install hangs or times outthe network — the npmmirror slide
Port 5173 is in usea dev server is already running. Vite takes 5174 — read the address
a white pageopen the Console. Read the first red line
Failed to resolve componentyou used <QuoteCard> but forgot to import it
my changes don't showyou edited dist/, or a different folder is running
live site: white page, 404s for /assets/…the site lives in a sub-folder — set base in vite.config.js
live site: 404 on reloadclient-side routing — the "Reload on /quotes" slide

The AI has read ten years of Vue tutorials — most of them old

Spot old Vue.

If the AI writes…It is…
new Vue({ el: '#app' })Vue 2 — ended December 2023. Will not run.
Vue.component(…) · this.$set · filters:Vue 2 only
import Vue from 'vue'Vue 2
data() { return {…} } · methods: {…}Options API — valid Vue 3, a different style. Don't mix the two.
<script setup> · ref() · computed() · defineProps()What we use ✓

Most "it doesn't work" with AI-written Vue is this table. Check the version before you check anything else.

Tell it once, at the start of every chat

Give the AI the rules.

This is a Vue 3 project created with create-vue and Vite.
Use the Composition API with <script setup>. No Options API, no Vue 2 syntax.
Pages live in src/views and are registered in src/router/index.js.
Reusable pieces live in src/components. Data lives in src/data.
Use semantic HTML: header, nav, main, footer, article, blockquote, cite.
Site-wide CSS is in src/assets/style.css. Component CSS goes in <style scoped>.
Never put passwords or API keys in this code — it all runs in the browser.
Explain every file you change.

The last two lines are for you. A key in Vue code is a published key — and you must be able to explain every line in your project presentation.

The question for your own project

Should your site use Vue?

Yes, if it has…

  • many items from one set of data
  • a search, a filter, a cart
  • things that change while you look

No, if it is…

  • four pages of text and images
  • already working, and done
  • one small widget — use way A

Not required, not extra marks by itself. A reason you can defend is what counts — either way.

Before you leave · check every box

Done when…

Where to look things up

vuejs.org/guide

in Chinese: cn.vuejs.org · router: router.vuejs.org · build: vite.dev

The official docs are better than any tutorial — and newer than what the AI learned from.

webtech.landrock.io/sessions

← → navigate · F fullscreen · P print · Copy never turns the page