Vue is a JavaScript framework for building user interfaces from reusable components. Vue 3 tracks reactive state and updates only the rendered parts that depend on it. A useful introduction shows a small working component, explains the template syntax, and distinguishes a frontend view from routing, authentication and backend data persistence. This example creates a minimal task list without relying on an external API.
Start a Vue project with the current supported tooling
Install a supported Node.js runtime, then use Vue’s official project creator and follow its interactive prompts. The generator configures a modern Vite-based development workflow. For a simple exercise you can decline optional router and state-management features. Review the generated project scripts instead of copying a command from an unrelated tutorial or assuming older Vue CLI templates are still the preferred path.
npm create vue@latest
cd my-vue-project
npm install
npm run dev
The project name will be whatever you choose in the generator; replace my-vue-project accordingly. The development server URL is printed in the terminal. This local server is intended for development, not production hosting. The official Vue quick start describes the current setup options.
Build a component with reactive state
<script setup>
import { ref } from "vue";
const newTask = ref("");
const tasks = ref([
{ id: 1, label: "Read the requirements" }
]);
let nextId = 2;
function addTask() {
const label = newTask.value.trim();
if (!label) return;
tasks.value.push({ id: nextId++, label });
newTask.value = "";
}
</script>
<template>
<main>
<h1>Tasks</h1>
<form @submit.prevent="addTask">
<label for="task">New task</label>
<input id="task" v-model="newTask" />
<button type="submit">Add</button>
</form>
<ul>
<li v-for="task in tasks" :key="task.id">
{{ task.label }}
</li>
</ul>
</main>
</template>
Place this code in the generated root component, usually src/App.vue. The ref wrapper stores reactive state. In JavaScript, update refs through .value; Vue templates automatically unwrap them for display. The v-model directive keeps the text input and reactive value synchronized, while @submit.prevent calls the handler without reloading the page.
Why keys, templates and event handlers matter
The v-for loop gives each task a stable numeric key so Vue can track item identity when the array changes. Avoid using the list position as a key when items can be inserted, deleted or reordered. Interpolated content such as {{ task.label }} is handled as text by Vue; avoid inserting user-supplied HTML through v-html unless a separate, audited sanitization policy exists.
Components are not a database
This task list is in browser memory. Refreshing the page restarts the initial data. To persist data, design an authenticated API and handle request loading, errors and authorization at the correct boundary. A backend should validate submitted data independently even if the Vue frontend already rejects blank text. The REST API example in the Spring Boot controller tutorial provides a small server-side contract that could be adapted for a Vue client.
Test behavior before styling the page
- Submit a task consisting only of spaces and confirm the list does not change.
- Add two valid tasks and confirm distinct keys and predictable ordering.
- Use keyboard navigation to reach the input and submit button.
- Reload the development page and confirm that this demo does not claim persistence.
Vue’s core value is declarative, reactive UI composition, not a guarantee that any particular app is fast or secure. The official Vue reactivity documentation describes how refs trigger updates and how Vue templates consume them. Learn components and data flow before adding routing, state stores, build optimizations or a production deployment pipeline.