Vue is a JavaScript framework for building interactive user interfaces. Its main idea is declarative rendering: a developer describes what should appear for a given application state, and Vue keeps relevant parts of the browser page in sync as that state changes. Understanding this behavior requires more than learning directives; it helps to know how Vue tracks dependencies, compiles templates and connects components.
This guide describes Vue 3 using its official documentation. Vue 2 reached end of support on December 31, 2023, so instructions written for Vue 2 should not be copied into a new project without checking the migration guidance. Vue can enhance part of an existing page or support a larger application. It does not require every site to become a client-rendered single-page application.
What “progressive framework” means in practice
Vue is called progressive because teams can adopt it in different ways. A small widget may be mounted inside an existing server-generated page without rebuilding the whole website. A larger application can use build tools, Single-File Components, routing and shared-state libraries. The official Vue 3 introduction distinguishes incremental enhancement, SPAs, server-side rendering and static-site generation rather than presenting one mandatory architecture.
The underlying browser platform still matters. HTML gives content meaning, CSS controls presentation and JavaScript implements interaction. Vue organizes those responsibilities through components and a reactive rendering system, but it does not automatically make forms accessible, authorize API requests or guarantee good performance.
Choose the smallest appropriate setup. A nontrivial app may benefit from Single-File Components and a build step. A simple counter in an existing website may only need Vue’s browser build. Adding a client-side router, state store and deployment pipeline to one small interaction can increase complexity without improving the user’s task.
Reactive state: how Vue detects changes
In the Composition API, ref() creates a reactive reference. In JavaScript, you read and change the contained value through .value. In Vue templates, ordinary top-level refs are automatically unwrapped for convenient interpolation and event handling. The Vue reactivity fundamentals explain how getters and setters allow Vue to track which effects depend on a value.
For example, after defining const count = ref(0), changing count.value++ causes Vue to schedule an update for a component that used the ref during rendering. Vue does not need a developer to manually find the affected text node and assign a new textContent value. It tracks dependencies and uses its renderer to apply the needed change.
reactive() creates a proxy for a suitable object, array or collection. Its behavior differs from a ref, especially when replacing a whole object or destructuring primitive properties. Copying state.count into an unrelated local number disconnects that variable from reactive tracking. Use ref(), toRefs() or another appropriate pattern when passing reactive values across functions.
DOM updates are scheduled and batched. Changing a ref does not necessarily update the browser’s DOM synchronously on the next line of JavaScript. When code genuinely needs to observe the updated DOM, the nextTick() helper can be used to await Vue’s update cycle. Avoid direct DOM manipulation when a declarative binding expresses the desired behavior more clearly.
Templates, directives and computed values
Vue templates resemble HTML and support expressions such as {{ count }} for displaying values. v-bind, commonly shortened to :, binds an attribute or property to JavaScript data. v-on, often written as @, listens for an event. v-if conditionally creates or removes rendered content, while v-show usually toggles CSS display behavior on an existing element. The correct choice depends on update frequency and lifecycle needs.
v-for renders repeated items. Use a stable, unique :key for stateful or reordered lists so Vue can keep item identity straight. Using an array position as the key can lead to confusing reuse when items are inserted, removed or reordered. Model the underlying records with identifiers where that behavior matters.
A computed value derives a result from reactive dependencies and is cached until those dependencies change. It is suitable for values such as the number of unfinished tasks. The official computed-properties guidance recommends keeping computed getters free of side effects. Network calls, writing storage and altering unrelated state belong in event handlers, lifecycle hooks or carefully chosen watchers rather than in a computed getter.
Watchers observe a specific reactive source when a side effect is needed. A watcher can refresh derived remote data or update an integration after an input changes, but it also requires cleanup and error handling. A simple value that can be computed from existing state should usually remain computed instead of becoming a second separately updated source of truth.
A complete Vue 3 Single-File Component example
This small task list uses <script setup>, refs, a computed count, v-model and a keyed loop. It assumes a Vue 3 project created with the official tooling. Save it as a component, such as App.vue, in a compatible Vite-based project. The sample stores information only in memory; it does not implement accounts, persistence or a remote API.
<script setup>
import { computed, ref } from 'vue'
const newTask = ref('')
const tasks = ref([
{ id: 1, text: 'Read Vue basics', done: false }
])
let nextId = 2
const remaining = computed(
() => tasks.value.filter(task => !task.done).length
)
function addTask() {
const text = newTask.value.trim()
if (!text) return
tasks.value.push({ id: nextId++, text, done: false })
newTask.value = ''
}
</script>
<template>
<main>
<h1>Practice tasks</h1>
<form @submit.prevent="addTask">
<label for="new-task">New task</label>
<input id="new-task" v-model="newTask" />
<button type="submit">Add</button>
</form>
<p>Remaining: {{ remaining }}</p>
<ul>
<li v-for="task in tasks" :key="task.id">
<label>
<input type="checkbox" v-model="task.done" />
{{ task.text }}
</label>
</li>
</ul>
</main>
</template>
When the user submits the form, the handler trims the entered text and adds an object to the reactive array. Vue then updates the list and computed count. Marking a checkbox changes task.done through v-model, which triggers the remaining-count recalculation. The form modifier prevents default navigation, while the label elements give inputs readable names.
The incremental identifier is only for this in-memory demonstration. A real application receiving tasks from a server should use stable identifiers from its data model and handle errors and duplicate submissions. The use of {{ task.text }} is text interpolation, which Vue escapes by default; rendering user-supplied HTML with v-html introduces a different security risk and requires a carefully controlled trust boundary.
How templates become DOM updates
Vue can compile a template into a render function that produces a virtual representation of the interface. During an initial mount, the renderer creates browser DOM nodes. Later, when reactive dependencies change, the component’s render effect runs again and the renderer patches the relevant nodes.
The official rendering-mechanism explanation describes a compiler-informed virtual DOM. Because Vue’s compiler can analyze which parts of a template are static or dynamic, it can generate patch flags and block structure that help the runtime avoid unnecessary work. That differs from a simplistic claim that Vue always rebuilds or compares every DOM node after every event.
Components also have lifecycle hooks. onMounted() runs after a component is mounted, while onUnmounted() can clean up listeners, timers or integrations. If a component creates an interval or subscribes to a browser event, it should arrange appropriate cleanup. Failing to release resources can cause stale updates and memory retention even if the reactive template syntax is correct.
Vue’s update mechanism is an implementation detail with practical consequences. It is better to measure a slow screen and identify the actual work being done than claim Vue is inherently faster than every alternative. Large lists, unnecessary watchers, expensive computations, oversized assets and network delays can slow an application regardless of the framework.
Options API versus Composition API
Vue 3 supports both Options API and Composition API. Options API organizes a component through sections such as data, computed, methods and mounted. Composition API uses imported functions such as ref(), computed() and onMounted() so related logic can be grouped and reused more flexibly.
These are not separate frameworks, nor is Options API categorically obsolete. Vue’s documentation notes that both styles are fully capable and share the underlying reactivity system. The team can choose based on experience, project scale and existing conventions. For larger Single-File Component applications, Composition API with <script setup> is commonly recommended by the Vue documentation.
A clear component boundary is more important than choosing whichever syntax is fashionable. Keep props as inputs, use component events for relevant communication with parents and avoid quietly mutating data owned by another component. Reusable composables are useful when logic is shared, but not every two-line operation needs to be turned into a separate abstraction.
Routing, state and server-side responsibilities
For a single-page application, Vue Router maps browser paths to components and supports navigation without a full page reload in common scenarios. It is an official ecosystem library, not a behavior that appears automatically in every minimal Vue application. A small embedded widget may not need client-side routing at all.
For shared state across components, props and local composables may be enough. The official Pinia state-management library can help when numerous views rely on the same state with predictable updates. Centralized state does not guarantee consistency with a remote database; the application must handle loading, errors and synchronization appropriately.
Vue handles the interface, not the server’s security decisions. An authenticated browser should not be able to retrieve another user’s records simply by changing a URL or component property. Server-side authorization, validation and protected sessions remain necessary. The distinction between different web-page purposes and rendering approaches helps determine whether an SPA, server rendering or simpler document page fits the task.
Server-side rendering can improve initial content delivery for some sites, but it adds hydration and deployment considerations. The HTML produced on the server must be compatible with the client’s expectations. A Vue application should also handle unavailable JavaScript or loading failures as appropriate to the intended users and business requirements.
Set up and verify a project with current tooling
The official Vue quick start documents the create-vue scaffolding tool for Vue 3, using Vite for a build-based application. At the time reviewed, the guide specifies compatible Node.js versions; confirm the current prerequisite before creating a project. The normal workflow is to scaffold, choose the features the project actually needs, install dependencies and start the development server:
npm create vue@latest
# Follow the prompts, then change into the new project folder:
npm install
npm run dev
This snippet assumes the terminal is already inside the generated project directory after answering the prompts; npm install should not be run in an unrelated folder. Development-server output gives the actual local URL. For a production build, the generated project normally uses npm run build and emits assets in dist, but deployment and server configuration remain separate steps.
Test the example component with keyboard navigation and ordinary invalid input, then check a production build. Add automated tests as complexity grows. Use Vue DevTools and browser developer tools to inspect reactive state and rendered components. Document dependencies, keep software updated and do not assume that a successful local demo is ready to process customer data.
Vue’s strength is a component-based interface with reactive updates and a flexible ecosystem. Understanding when a ref changes, when a computed value runs and how the renderer updates the DOM gives developers a more durable skill than memorizing directives without testing them. A good Vue application remains grounded in web standards, accessible design and correct server-side behavior.