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> </template>
<script> <script>
import { mapState, mapActions } from 'vuex'
export default { export default {
name: 'Sort', name: 'Sort',
data () { data () {
return { return {
sortBy: null,
options: [ options: [
{ {
label: 'Name', 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> </script>

View File

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