11.2 Getters for Todo and Complete

This commit is contained in:
Fredrick W Warren 2021-02-10 09:49:35 -08:00
parent 2f230d473e
commit 36f6285e24
2 changed files with 23 additions and 6 deletions

View File

@ -1,12 +1,12 @@
<template> <template>
<q-page class="q-pa-md"> <q-page class="q-pa-md">
<q-list <q-list
v-if="Object.keys(tasks).length" v-if="Object.keys(tasksTodo).length"
separator separator
bordered> bordered>
<task <task
v-for="(task, key) in tasks" v-for="(task, key) in tasksTodo"
:key="key" :key="key"
:task="task" :task="task"
:id="key" :id="key"
@ -42,11 +42,11 @@ export default {
}, },
data () { data () {
return { return {
showAddTask: true showAddTask: false
} }
}, },
computed: { computed: {
...mapGetters('tasks', ['tasks']) ...mapGetters('tasks', ['tasksTodo'])
} }
} }
</script> </script>

View File

@ -56,8 +56,25 @@ const actions = {
} }
const getters = { const getters = {
tasks: (state) => { tasksTodo: (state) => {
return state.tasks const tasks = {}
Object.keys(state.tasks).forEach(function (key) {
const task = state.tasks[key]
if (!task.completed) {
tasks[key] = task
}
})
return tasks
},
tasksCompleted: (state) => {
const tasks = {}
Object.keys(state.tasks).forEach(function (key) {
const task = state.tasks[key]
if (task.completed) {
tasks[key] = task
}
})
return tasks
} }
} }