Web Development

Vue

Introduction to Vue.js options vs composition API, tutorial, router, and state management.

Vue

Concepts

A .vue files may have HTML, CSS, JS template syntax inside.

  • <template></template> is for HTML structure
  • <style></style> is for CSS style. scoped attribute is used to limit the style to the current component
  • <script></script> is for JavaScript script. setup attribute is used to limit the script to the current component

Vue have two code modes, Options and Composition Mode. But in this documentation. We use composition

OptionsComposition
Older and more structuralNewer and more flexible
More codes, with export in script for setupLess code, using <script setup>

Nuxt

Comprehensive framework for Vue.js (Highly recommended)

The Flow

Server to Client Rendering Pipeline

  1. The server pre-render the HTML in a Node.js, convert the HTML to a string, and send it to the client
  2. The client receive the HTML string, convert it back to HTML, and render it
  3. The client's browser download the Vue bundle
  4. Hydration: Vue walks through the existing HTML and attach event listeners and reactivity logic to the DOM. Also checking with the server that both client and server have the same HTML.
  • onMounted is a hook only on the client after the component has been mounted to the DOM. THis is the safe place to touch window, document or start animations.
  • isMounted is usually a hard-coded variable to sync between server and client that the component has been mounted. Which is when onMounted is called.
  • useMounted is a composable function that returns a boolean value that the component has been mounted. This is not a built-in function into Vue, it helps to prevent "Hydration Mismatch" error.

Getting started

Run the code below to get started

npm install -g @vue/cli
vue create my-vue-app
cd my-vue-app
npm run dev
# or
npm run serve
# For deployment
npm run build

Then, select manually select feature to suits your need. Router, Pinia (global state management) is recommended. Starter template will be at port 8080

Project Structure
vue-app/
├── public/
├── src/
│   ├── assets/
│   ├── components/ # For reusable components
│   │   └── ButtonComponent.vue 
│   ├── router/
│   │   └── index.js
│   ├── store/
│   │   └── index.js
│   ├── views/ # For pages
│   │   ├── HomeView.vue
│   │   └── AboutView.vue
│   ├── App.vue
│   └── main.js
├── .gitignore
├── package.json
└── vue.config.js

Reactivity Syntax Tutorial

ConceptHow
Declarative renderinglet vueVariable = reactive({ count: 0 }) or ref for singular variable
Attribute bindings:class="vueVariable" or v-bind:class="vueVariable" both are the same
Event listeners@click="vueVariable++" or v-on:click="vueVariable++" both are the same
Form bindingsv-model="vueVariable"
Conditional renderingv-if="vueVariable" or v-else
List renderingv-for="vueVariable in array"
Computed propertycomputed(() => vueVariable) outputs a function with reactive variable changes
LifecycleonMounted(() => { ... }) run a function when component is mounted
Template refsref="vueVariable" manually access DOM after elements being mounted
Watcherswatch(vueVariable, () => { ... }) run a function when reactive variable changes
Componentsimport ChildComp from './ChildComp.vue'
Propsprops="vueVariable" pass data to child component
Emitsemits("vueVariable") emit data to parent component
Slotsslot="vueVariable" pass down template fragments to child component

The code below shows the implementation combination of the fundamentals concepts.

Router

To control and remember URL routes on the site

Pinia

Official global state management tool for vue

Component library

PrimeVue

Primevue is a framework to make modern UI by adding components into vue files. Visit PrimeVue to get started.

Copyright © 2026 Nut17. All rights reserved.