Build a Todo List App using VueJS
Last Updated :
02 May, 2024
This article provides an in-depth exploration of creating a Todo List application using Vue.js. It covers various aspects of building the application, whether you're new to Vue.js or looking to expand your skills, this comprehensive guide offers valuable insights and practical instructions to help you create a fully functional Todo List application.
Steps to setup the ToDo list App Project
Step 1: Initialize Vue Project
npm install -g @vue/cli
vue create todo-list-vue
cd todo-list-vue
Project Structure:

Package.json file:
"dependencies": {
"core-js": "^3.8.3",
"vue": "^3.4.24"
},
Approach
- Event Handling: Integrated Vue.js event handling for tasks such as adding, editing, and deleting.
- Dynamic Rendering: Used Vue.js directives like v-for for dynamic rendering of tasks and v-bind for conditional styling.
- State Management: Managed application state using Vue.js data properties for efficient data handling.
- Table Layout: Implemented a table-like layout using CSS Grid for the task list.
Example: This example shows the creation of todo app in vuejs.
CSS
/* style.css */
header {
background-color: rgb(48, 47, 47);
color: white;
padding: 10px 0;
}
.navbar {
display: flex;
justify-content: center;
}
.logo img {
height: 40px;
width: auto;
}
/* Todo list styles */
#app {
font-family: Arial, sans-serif;
}
.container {
margin: 20px auto;
max-width: 600px;
}
.title {
text-align: center;
font-size: 36px;
font-weight: bold;
}
hr {
border: 1px solid #ccc;
}
.input-group {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.form-control {
flex: 1;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
margin-right: 10px;
}
.btn-success {
border-radius: 5px;
padding: 10px 20px;
background-color: #28a745;
color: white;
border: none;
cursor: pointer;
}
.todo-table {
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
}
.table-header {
display: flex;
background-color: #f0f0f0;
padding: 10px;
}
.table-cell {
flex: 1;
padding: 10px;
font-size: 18px;
}
.table-body {
display: grid;
}
.table-row {
display: flex;
border-top: 1px solid #ccc;
}
.even-row {
background-color: #f9f9f9;
}
.completed {
text-decoration: line-through;
}
.completed-cell {
color: #888;
}
.btn {
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
.btn-primary {
background-color: #007bff;
color: white;
border: none;
}
.btn-info {
background-color: #17a2b8;
color: white;
border: none;
}
.btn-danger {
background-color: #dc3545;
color: white;
border: none;
}
button{
margin-left:3px;
}
JavaScript
//App.vue
<template>
<div id="app">
<header>
<nav class="navbar">
<div class="logo">
<img src=
"https://media.geeksforgeeks.org/gfg-gg-logo.svg"
alt="GeeksforGeeks logo">
</div>
</nav>
</header>
<div class="container">
<h1 class="title">TODO LIST</h1>
<hr>
<div class="input-group">
<input type="text"
class="form-control"
placeholder="Add item..."
v-model="userInput" @keyup.enter="addItem">
<button class="btn btn-success"
@click="addItem">ADD</button>
</div>
<div class="todo-table">
<div class="table-header">
<div class="table-cell">Task</div>
<div class="table-cell">Actions</div>
</div>
<div class="table-body">
<div class="table-row" v-for="(item, index) in filteredList"
:key="index" :class="{ 'even-row':
index % 2 === 0, 'completed': item.completed }">
<div class="table-cell" :class="{ 'completed-cell':
item.completed }">{{ item.value }}</div>
<div class="table-cell">
<button class="btn btn-primary"
@click="toggleCompleted(index)">
{{ item.completed ? 'Undo' : 'Complete' }}
</button>
<button class="btn btn-info"
@click="editItem(index)">Edit</button>
<button class="btn btn-danger"
@click="deleteItem(index)">Delete</button>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
userInput: '',
searchInput: '',
list: []
};
},
computed: {
filteredList() {
return this.list.filter(item => item.value.toLowerCase()
.includes(this.searchInput.toLowerCase()));
}
},
methods: {
addItem() {
if (this.userInput.trim() !== '') {
const newItem = {
id: Math.random(),
value: this.userInput.trim(),
completed: false
};
this.list.push(newItem);
this.userInput = '';
}
},
deleteItem(index) {
this.list.splice(index, 1);
},
editItem(index) {
const editedTodo = prompt('Edit the todo:');
if (editedTodo !== null && editedTodo.trim() !== '') {
this.list[index].value = editedTodo.trim();
}
},
toggleCompleted(index) {
this.list[index].completed = !this.list[index].completed;
}
}
};
</script>
<style src="./style.css">
</style>
JavaScript
import Vue from "vue";
import App from "./App.vue";
import "./styler.css";
Vue.config.productionTip = false;
new Vue({
render: (h) => h(App),
}).$mount("#app");
Run the Development Server: Start the development server. This will compile your Vue.js code and launch a local server.
npm run serve
Once the server is running, open your web browser and go to http://localhost:8080 (or whatever port is specified in the terminal). You should see your Vue.js Todo List application running.
Output:

Similar Reads
Building A Weather App Using VueJS We will explore how to create a weather application using Vue.js. We'll cover an approach to fetching weather data, displaying current weather conditions, and forecasting. By the end of this guide, you'll have a fully functional weather application that displays current weather information and forec
6 min read
Building a Shopping List with VueJS The following approach covers how to build a simple shopping list app with VueJs. Vue (or Vue.js) is an open-source JavaScript framework geared towards building user interfaces, it was created by Evan You.Prerequisites:Basic understanding of HTML.Basic knowledge of CSSBasic knowledge of JavaScriptIn
3 min read
Todo List App Using JavaScript This To-Do List app helps users manage tasks with features like adding, editing, and deleting tasks. By building it, you'll learn about DOM manipulation, localStorage integration, and basic JavaScript event handling.What We Are Going To CreateWe are creating a Todo application whereUsers can add, ed
7 min read
Build a Movie App with VueJS We will build a movie application using Vue.js. By the end, you'll have a fully functional movie app that will allow users to search for movies, view their details, and get information such as title, year, rating, and plot. Prerequisites:Vue.jsNode.js and npm are installed on your system.Approach Vu
5 min read
Build Random Quote Generator using VueJS We are going to build a Random Quote Generator using Vue.js. This application will fetch random quotes from an API and display them on the screen. Users will have the option to copy the quote to their clipboard or generate a new random quote. Prerequisites:Node.jsVue.jsApproachWe'll create a Vue.js
4 min read
Todo List Application using MERN Todo list web application using MERN stack is a project that basically implements basic CRUD operation using MERN stack (MongoDB, Express JS, Node JS, React JS). The users can read, add, update, and delete their to-do list in the table using the web interface. The application gives a feature to the
8 min read