13.6 Link the Sort Dropdown to the Vuex Store State

This commit is contained in:
Fredrick W Warren 2021-02-11 07:42:29 -08:00
parent f4704ac990
commit b2f481d4b0
2 changed files with 22 additions and 1 deletions

View File

@ -12,11 +12,12 @@
</template>
<script>
import { mapState, mapActions } from 'vuex'
export default {
name: 'Sort',
data () {
return {
sortBy: null,
options: [
{
label: 'Name',
@ -28,6 +29,20 @@ export default {
}
]
}
},
computed: {
...mapState('tasks', ['sort']),
sortBy: {
get () {
return this.sort
},
set (value) {
this.setSort(value)
}
}
},
methods: {
...mapActions('tasks', ['setSort'])
}
}
</script>

View File

@ -40,6 +40,9 @@ const mutations = {
},
setSearch (state, value) {
state.search = value
},
setSort (state, value) {
state.sort = value
}
}
@ -60,6 +63,9 @@ const actions = {
},
setSearch ({ commit }, value) {
commit('setSearch', value)
},
setSort ({ commit }, value) {
commit('setSort', value)
}
}