13.6 Link the Sort Dropdown to the Vuex Store State
This commit is contained in:
		
							parent
							
								
									f4704ac990
								
							
						
					
					
						commit
						b2f481d4b0
					
				| @ -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> | ||||||
|  | |||||||
| @ -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) | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user