[Vuejs]-How to link routes list with store variable?

0👍

You would need to add a getter for your list. Something like:

export default new Vuex.Store({
   state: {
      routes_list: []
   },
  getters: {
    routesList: state => {
      return state.routes_list;
    }
  }
})

Then you could import your Store in your router.js and use the created getter to receive the list:

// maybe your path is different
import Store from '@/store/index';
export default new Router({
   routes: Store.getters.routesList
})

I’ve didn’t tested the router code, maybe you need to do some correction.

Leave a comment