11.5 Setup an Action & Mutation to set the search property

This commit is contained in:
Fredrick W Warren 2021-02-10 12:33:21 -08:00
parent a3a551192d
commit bcc2b87e6e
2 changed files with 13 additions and 3 deletions

View File

@ -16,7 +16,7 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex' import { mapState, mapActions } from 'vuex'
export default { export default {
name: 'Search', name: 'Search',
@ -26,10 +26,14 @@ export default {
get () { get () {
return this.search return this.search
}, },
set (value) {} set (value) {
this.setSearch(value)
} }
} }
},
methods: {
...mapActions('tasks', ['setSearch'])
}
} }
</script> </script>

View File

@ -36,6 +36,9 @@ const mutations = {
}, },
addTask (state, payload) { addTask (state, payload) {
Vue.set(state.tasks, payload.id, payload.task) Vue.set(state.tasks, payload.id, payload.task)
},
setSearch (state, value) {
state.search = value
} }
} }
@ -53,6 +56,9 @@ const actions = {
task: task task: task
} }
commit('addTask', payload) commit('addTask', payload)
},
setSearch ({ commit }, value) {
commit('setSearch', value)
} }
} }