What is Vue?
Builds on top of standard HTML, CSS, and JavaScript, providing a declarative and component-based programming model.Declarative Rendering
Vue extends HTML with a template syntax that describes the output based on JavaScript state. What you write in the template directly reflects what appears on screen.
Reactivity
Vue automatically tracks JavaScript state changes and efficiently updates the DOM — without you needing to do anything manually.
Setting Up with Vite
| Command | Description |
|---|---|
node -v | Check if Node is installed. |
npm create vue@latest | Create Vue project with official installer (create-vue). Choose TypeScript, Router, Pinia, etc. |
npm install | Install project dependencies. |
npm run dev | Start development server. |
Vue uses create-vue (based on Vite) as the official scaffolding tool, just like React uses Vite.
Single File Component (.vue)
Vue uses.vue files called SFC (Single File Component). It’s the equivalent of .jsx in React.
Each .vue file encapsulates the three parts of a component in one place:
- Structure
- Example
<script>— JavaScript logic<template>— HTML structure<style>— CSS styles (optionally withscoped)
API Styles: Options vs Composition
Vue has two ways to write components. Both work — they’re different interfaces over the same underlying system.- Options API
- Composition API (Recommended)
Defines component logic via an object of options (
data, methods, mounted…). More familiar for those coming from object-oriented programming.Reactivity: ref and reactive
In Vue, the equivalent of React’s useState is ref(). When the value changes, the interface updates automatically.
- ref()
- reactive()
For simple values (string, number, boolean). To change, use
.value in script — in template, Vue accesses automatically without .value.Template Syntax
Vue’s template uses HTML with special directives. In React you use JSX with pure JavaScript — in Vue you use attributes prefixed withv- or symbols like @ and :.
| Syntax | React Equivalent | Description |
|---|---|---|
{{ value }} | {value} | Interpolates a reactive value in HTML. |
v-bind:href or :href | href={value} | Binds an attribute to a reactive value. |
v-on:click or @click | onClick={fn} | Listens to DOM events. |
v-if / v-else | {cond && <El />} | Conditional rendering. |
v-for | {arr.map(...)} | Renders a list of elements. |
v-model | value + onChange | Two-way binding in inputs — binds and updates state automatically. |
Props
Just like in React, props pass data from parent component to child. In Vue with Composition API, you declare them withdefineProps().
To emit events back to the parent (like a callback), use defineEmits() — the equivalent of passing a function as a prop in React.
Lifecycle Hooks
The equivalent of React’suseEffect(fn, []) (execute on mount) is Vue’s onMounted().
| Vue Hook | React Equivalent | When Called |
|---|---|---|
onMounted() | useEffect(fn, []) | After component is inserted in DOM. |
onUpdated() | useEffect(fn, [dep]) | After a reactive update re-renders the component. |
onUnmounted() | useEffect(() => () => cleanup, []) | When component is removed from DOM. Ideal for cleaning timers and listeners. |
Computed Properties
A value derived from reactive state. Vue automatically recalculates when the dependency changes — and caches it until it actually changes. Equivalent to React’suseMemo(), but without manually declaring dependencies.
Watchers
Thewatch executes a function every time a reactive value changes — equivalent to React’s useEffect(fn, [dep]).
Use when you need to react to changes with side effects: save to localStorage, call APIs, start animations.
Routing with Vue Router
The equivalent of React Router Dom is Vue Router — Vue’s official routing library. Install:npm install vue-router@4
| Vue Router | React Router Equivalent | Use |
|---|---|---|
createRouter() | createBrowserRouter() | Creates router with route list. |
<RouterView /> | RouterProvider | Where the current route’s page/component is rendered. |
<RouterLink /> | <Link /> | Navigation link without page reload. |
useRouter() | useNavigate() | Navigate programmatically between routes. |
useRoute() | useSearchParams() | Access params and query from current route. |
Next Steps
Global State
Pinia is Vue’s official state management library — equivalent to Redux/Zustand in React. Simpler and more modern than Vuex (old standard).
Forms
VeeValidate + Zod or Yup for complex form validation.
Data Fetching
VueUse (collection of utility composables) or TanStack Query (same lib as React Query, but for Vue).
Testing
Vitest + Vue Testing Library + Cypress for e2e tests.
Vue on Server
Nuxt.js is the Vue framework for SSR/SSG — equivalent to Next.js for React. Vue market standard.
UI Components
Vuetify, PrimeVue, or shadcn-vue for ready-made component libraries.