|
22 | 22 | <div class="row"> |
23 | 23 | <div class="column"> |
24 | 24 | <div class="card"> |
25 | | - <div class="row"> |
| 25 | + <div class="row" v-for="(task, i) in tasks" :key="i" :class="{ 'task-done': task.done }"> |
26 | 26 | <div class="column column-20"> |
27 | | - <button class="button-check button-clear"> |
| 27 | + <button class="button-check button-clear" @click="toggleTask(i)"> |
28 | 28 | |
29 | 29 | </button> |
30 | 30 | </div> |
31 | 31 | <div class="column column-80"> |
32 | | - <h3>Buy Milk</h3> |
| 32 | + <h3 class="no-margin">{{ task.title }}</h3> |
33 | 33 | </div> |
34 | 34 | </div> |
35 | | - <div class="row task-done"> |
36 | | - <div class="column column-20"> |
37 | | - <button class="button-check button-clear"> |
38 | | - |
39 | | - </button> |
40 | | - </div> |
41 | | - <div class="column column-80"> |
42 | | - <h3>Buy Milk</h3> |
43 | | - </div> |
| 35 | + <div v-if="!tasks.length"> |
| 36 | + <h3 class="no-margin">No tasks, yet.</h3> |
44 | 37 | </div> |
45 | 38 | </div> |
46 | 39 | </div> |
47 | 40 | </div> |
48 | 41 | <div class="row add-task"> |
49 | 42 | <div class="column text-center"> |
50 | | - <button class="button"> |
| 43 | + <button class="button" @click="addTask()"> |
51 | 44 | <h3 class="no-margin">Add Task</h3> |
52 | 45 | </button> |
53 | 46 | </div> |
|
61 | 54 | </template> |
62 | 55 |
|
63 | 56 | <script> |
| 57 | +/** |
| 58 | + * New task entity |
| 59 | + * @param {string} title - The title of this task |
| 60 | + * @param {boolean} title - Whether the task is done or not |
| 61 | + */ |
| 62 | +function Task(title, done) { |
| 63 | + this.title = title || 'New Task'; |
| 64 | + this.done = done || false; |
| 65 | +} |
| 66 | +
|
64 | 67 | export default { |
65 | 68 | name: 'app', |
66 | 69 | data () { |
67 | 70 | return { |
68 | | - message: 'Hello World!' |
| 71 | + tasks: [], |
| 72 | + } |
| 73 | + }, |
| 74 | + methods: { |
| 75 | + /** |
| 76 | + * Add a new task to the array of tasks |
| 77 | + */ |
| 78 | + addTask () { |
| 79 | + const newTask = new Task(); |
| 80 | + this.tasks.push(newTask); |
| 81 | + }, |
| 82 | + /** |
| 83 | + * Toggle the `done` status of a task |
| 84 | + * @param {number} i - Index of the task |
| 85 | + */ |
| 86 | + toggleTask (i) { |
| 87 | + this.tasks[i].done = !this.tasks[i].done; |
69 | 88 | } |
70 | 89 | } |
71 | 90 | } |
|
0 commit comments