A to-do app may be simple, but itโs one of the best projects to understand how Vue 3โs Composition API works. It teaches reactivity, component structure, state management, and event handlingโall the essentials you need to grow into a confident Vue developer. Letโs walk through building a clean and functional to-do app step-by-step.
๐ญ. ๐ฆ๐ฒ๐๐๐ถ๐ป๐ด ๐จ๐ฝ ๐๐ต๐ฒ ๐ฉ๐๐ฒ ๐ฏ ๐ฃ๐ฟ๐ผ๐ท๐ฒ๐ฐ๐
Start by creating a new Vue project with Vite:
npm create vue@latest
cd your-project
npm install
npm run dev
Inside your src directory, youโll work primarily in App.vue or separate components if you prefer a modular approach.
๐ฎ. ๐จ๐๐ถ๐ป๐ด ๐๐ต๐ฒ ๐๐ผ๐บ๐ฝ๐ผ๐๐ถ๐๐ถ๐ผ๐ป ๐๐ฃ๐ ๐ณ๐ผ๐ฟ ๐ฆ๐๐ฎ๐๐ฒ
With the Composition API, we use ref() and reactive() to track reactive data. For a to-do list, we need:
- An input field for new tasks
- A list to store all tasks
- Methods to add, toggle, and delete tasks
import { ref } from \'vue\';
const newTask = ref(\'\');
const tasks = ref([]);
๐ฏ. ๐๐๐ถ๐น๐ฑ๐ถ๐ป๐ด ๐๐ต๐ฒ ๐๐ฑ๐ฑ ๐ง๐ฎ๐๐ธ ๐๐๐ป๐ฐ๐๐ถ๐ผ๐ป
This function pushes a new task into the array and clears the input:
const addTask = () => {
if (!newTask.value.trim()) return;
tasks.value.push({
id: Date.now(),
text: newTask.value,
completed: false
});
newTask.value = \'\';
};
๐ฐ. ๐ง๐ผ๐ด๐ด๐น๐ถ๐ป๐ด & ๐๐ฒ๐น๐ฒ๐๐ถ๐ป๐ด ๐ง๐ฎ๐๐ธ๐
const toggleTask = (id) => {
const task = tasks.value.find(t => t.id === id);
task.completed = !task.completed;
};
const deleteTask = (id) => {
tasks.value = tasks.value.filter(t => t.id !== id);
};
๐ฑ. ๐๐ฟ๐ฒ๐ฎ๐๐ถ๐ป๐ด ๐๐ต๐ฒ ๐ง๐ฒ๐บ๐ฝ๐น๐ฎ๐๐ฒ
Use Vueโs directives to bind the UI:
<input v-model=\"newTask\" @keyup.enter=\"addTask\" placeholder=\"Add a task...\" />
<ul>
<li v-for=\"task in tasks\" :key=\"task.id\">
<input type=\"checkbox\" v-model=\"task.completed\" @change=\"toggleTask(task.id)\" />
<span :class=\"{ \'line-through\': task.completed }\">{{ task.text }}</span>
<button @click=\"deleteTask(task.id)\">Delete</button>
</li>
</ul>
Tailwind or simple CSS can be used to style it.
๐ฒ. ๐๐ถ๐ป๐ฎ๐น ๐ง๐ต๐ผ๐๐ด๐ต๐๐
This small project reveals the power of the Composition APIโclean logic, reusable functions, and a predictable state flow. Once comfortable, you can extend the app with localStorage, animations, filters, or even move logic to composables.
Building a to-do app in Vue 3 is a perfect foundation for mastering more advanced web applications.
If you are looking for any services related to Website Development, App Development, Digital Marketing and SEO, just email us at nchouksey@manifestinfotech.com
#Vuejs #Vue3 #CompositionAPI #TodoApp #JavaScript #FrontendDevelopment #WebDevelopment #VueTutorial #CodingProjects #VueDevelopers #JSDeveloper #LearnVue #ModernFrontend #VueApps #DeveloperTips #VueEcosystem #BeginnerProjects #CleanCode #WebAppDevelopment #ProgrammingBasics
