Search code examples
javascriptvue.jsvuexnuxt.js

How to Map sub-State in nuxtjs


I have created a state ~/store/modules/general/index.js

There are get_info and get_pages Actions,

states info and pages,

When i use

...mapActions({
getInfo: 'modules/general/get_info'
getPages: 'modules/general/get_pages'
})

Works fine, but when i try to access it via

...mapState({
Info: 'modules/general/info'
Pages: 'modules/general/pages'
})

Return undefined

When i use

...mapState({
modules: 'modules'
})

this return all my substates plz help


Solution

  • Try to map the state twice for both info, pages states like,

    computed: {
        ...mapState('modules/general/info', ['get_info']),
        ...mapState('modules/general/pages', ['get_pages']) 
    }
    

    Another way you can map the states like,

    computed: {
      ...mapState('modules/general', {
        info: state => state.info,
        pages: state => state.pages
      })
    },
    

    Refer Binding-helpers-with-namespace