[Vuejs]-How to set and use router in Vuex with Nuxt.js

4👍

First you need to do is check, that your folder structure is properly made to have that number of params. Look to the docs for that => https://nuxtjs.org/guide/routing

Next you can pass your route params as an argument in your dispatch method:

  asyncData({ store, params }) {
    store.dispatch('loadAPIData', {
      city: params.city,
      company: params.company,
      dealSlug: params.dealSlug
    })
  },

And in your store take the payload in a second parameter:

export const actions = {
  loadAPIData({ commit }, {city, company, dealSlug}) {
    ...
  }
}

You can read more about Vuex payload here => https://vuex.vuejs.org/guide/actions.html#dispatching-actions

👤Szymon

Leave a comment