Explain it simply
Production Project: Task Dashboard, in plain language
Split the project into TaskForm, TaskList, TaskItem, and FilterBar components. Store tasks in a Pinia store and compute filteredTasks as a getter. Add dashboard and task detail routes in Router, and check form accessibility, the empty state, and error handling.
Problem → Why → Solution
The problem — why this concept matters
Writing all the store logic inside a UI component
A common mistake
Skipping keyboard focus and form labels
Core concept — understand how it works
Combine components, props, events, computed, a custom composable, Router, and Pinia to build a task dashboard.
- project requirements
- components, state, and services
- tested UI
Break a feature down into components
Core syntax or pattern
// stores/tasks.js
import { defineStore } from 'pinia'
export const useTasksStore = defineStore('tasks', {
state: () => ({ tasks: [], filter: 'all' }),
getters: {
visible: (state) => state.tasks.filter((task) =>
state.filter === 'all' ||
(state.filter === 'done' ? task.done : !task.done)
)
},
actions: {
add(title) {
this.tasks.push({ id: crypto.randomUUID(), title, done: false })
},
toggle(id) {
const task = this.tasks.find((item) => item.id === id)
if (task) task.done = !task.done
}
}
})Combine components, props, events, computed, a custom composable, Router, and Pinia to build a task dashboard.
Read the code step by step
- project requirements
// stores/tasks.jsSplit the project into TaskForm, TaskList, TaskItem, and FilterBar components. Store tasks in a Pinia store and compute filteredTasks as a getter. Add dashboard and task detail routes in Router, and check form accessibility, the empty state, and error handling.
- components, state, and services
actions: {Combine components, props, events, computed, a custom composable, Router, and Pinia to build a task dashboard.
- tested UI
})Apply Production Project: Task Dashboard in a small example and test normal, edge, and failure cases.
- project requirements
- components, state, and services
- tested UI
Success
Break a feature down into components
Failure
Writing all the store logic inside a UI component
Let's break it down simply
Split the project into TaskForm, TaskList, TaskItem, and FilterBar components. Store tasks in a Pinia store and compute filteredTasks as a getter. Add dashboard and task detail routes in Router, and check form accessibility, the empty state, and error handling.
// stores/tasks.js
import { defineStore } from 'pinia'
export const useTasksStore = defineStore('tasks', {
state: () => ({ tasks: [], filter: 'all' }),
getters: {
visible: (state) => state.tasks.filter((task) =>
state.filter === 'all' ||
(state.filter === 'done' ? task.done : !task.done)
)
},
actions: {
add(title) {
this.tasks.push({ id: crypto.randomUUID(), title, done: false })
},
toggle(id) {
const task = this.tasks.find((item) => item.id === id)
if (task) task.done = !task.done
}
}
})A filterable task dashboard with persistent component stateTry it yourself
Finish building task add/toggle/delete, all/open/done filters, a detail route, and localStorage persistence.
Vue Best Practices — Vue.js
Real-world usage
How to apply it in a real project
Apply Production Project: Task Dashboard in a small example and test normal, edge, and failure cases.
Mini challenge
Build it yourself
Finish building task add/toggle/delete, all/open/done filters, a detail route, and localStorage persistence.
- Rebuild the example without copying it
- Test a normal input and an edge case
- Predict the compiler or output result before running it
// stores/tasks.js
import { defineStore } from 'pinia'
export const useTasksStore = defineStore('tasks', {
state: () => ({ tasks: [], filter: 'all' }),
getters: {
visible: (state) => state.tasks.filter((task) =>
state.filter === 'all' ||
(state.filter === 'done' ? task.done : !task.done)
)
},
actions: {
add(title) {
this.tasks.push({ id: crypto.randomUUID(), title, done: false })
},
toggle(id) {
const task = this.tasks.find((item) => item.id === id)
if (task) task.done = !task.done
}
}
})Expected: Break a feature down into components
Show hint
Apply Production Project: Task Dashboard in a small example and test normal, edge, and failure cases.
Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- project requirements → components, state, and services → tested UI
- Combine components, props, events, computed, a custom composable, Router, and Pinia to build a task dashboard.
- Writing all the store logic inside a UI component
- Apply Production Project: Task Dashboard in a small example and test normal, edge, and failure cases.
Vue Best Practices — Vue.js