Vue2: Dynamic To-Do List
Welcome to this Vue.js To-Do App lab! In this exercise, you'll get hands-on experience building a dynamic to-do app using Vue.js. By the end of this lab, you'll have a functioning app where you can add, delete, and mark tasks as complete.
Objective
Build a simple to-do app where tasks can be added to a list, marked as complete, and deleted.
Instructions
-
Project Setup
- Start by setting up a new Vue instance. Remember to target the appropriate element in your HTML to bind your Vue app.
-
Creating Tasks
- Implement an input field (
task-input
) where tasks can be entered. - Add a button (
add-task
) to submit new tasks to a list.
- Implement an input field (
-
Displaying Tasks
- Use a
ul
element (task-list
) to display the tasks. - Utilize the
v-for
directive to loop through tasks and display each one as ali
element in the list.
- Use a
-
Task Structure
- Each task in the list should come with a checkbox (
task-checkbox
). Use this to mark tasks as complete. - Include a delete button (
delete-button
) on each task to allow for its removal.
- Each task in the list should come with a checkbox (
-
Task Management
- Make use of Vue.js directives like
v-for
to dynamically display tasks from the list. - Use
v-if
orv-show
to conditionally display elements based on certain criteria. For instance, you might want to show a message if there are no tasks in the list. - When a task is marked as complete (checkbox checked), the text of the task should be struck through.
- Clicking the delete button should remove the task from the list.
- Make use of Vue.js directives like
-
Vue.js Directives
- For dynamic management of the task list, leverage Vue.js's built-in directives, particularly
v-for
for looping through the list of tasks, andv-if
for conditional rendering.
- For dynamic management of the task list, leverage Vue.js's built-in directives, particularly
-
Final Notes
- Remember, when updating the input field in Vue, the internal Vue state won't update just by setting the value using vanilla JavaScript. Ensure you're updating the Vue state correctly.
- Be mindful of the Vue reactivity system. When you modify the data, Vue will automatically update the DOM. So, be sure to structure your data and methods in a way that takes advantage of this feature.
All set? Let's get started and build a dynamic to-do app with Vue.js!
Challenges Information
Challenge 1: Task Input
Create an input field where the user can type in new tasks. This input should have an id
of task-input
.
Challenge 2: Add Task Button
Implement a button with the id
of add-task
. When clicked, it should add the task typed into task-input
to a list of tasks. Remember to handle Vue's internal state for the input, so when its value changes, it should be properly updated in Vue's state.
Challenge 3: Task List Display
Design a ul
element with the id
of task-list
which will be responsible for displaying the list of tasks.
Challenge 4: Task Structure in List
Upon adding a task, it should appear in the task-list
as a li
element. This li
element should have a checkbox to indicate if a task is completed. This checkbox must contain a class
named task-checkbox
.
Challenge 5: Delete Task Button
Each li
task item should have its own button to delete that specific task. This button should have a class
of delete-button
.
Challenge 6: Marking a Task as Complete
When a task is marked as complete (by checking the checkbox), the text of the task should be struck through. This indicates that the task has been completed.
Challenge 7: Deleting a Task
Upon clicking the delete-button
, the specific task should be removed from the task-list
. Make sure that when a task is deleted, it disappears from the list.