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 or mapGetters and mapActions helpers from the vuex package.
  • If you’re using the createNamespacedHelpers method, use it to create mappers for the todos module.
  • Spread the mapGetters result inside the computed object definition with the getTodos getters.
  • Spread mapActions result inside the methods object definition with the fetchTodos 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 1200+ tech skills courses.