Solution: Vuex Mapping Helpers
Here’s the solution of how to convert a component to use Vuex Mapping Helpers.
We'll cover the following
Solution
Your task was to modify the App.vue
file to use Vuex mapping helpers instead of accessing store values and methods directly. Here are the required changes:
For the src/App.vue
file:
- Import the
createNamespacedHelpers
ormapGetters
andmapActions
helpers from thevuex
package. - If you’re using the
createNamespacedHelpers
method, use it to create mappers for thetodos
module. - Spread the
mapGetters
result inside thecomputed
object definition with thegetTodos
getters. - Spread
mapActions
result inside themethods
object definition with thefetchTodos
action.
Let’s run the widget below to understand how the solution above works.
Note: The code below may take a while to run. When the server starts, go to the app URL, and see the output.
Get hands-on with 1400+ tech skills courses.