最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Map sub-State in nuxtjs - Stack Overflow

programmeradmin9浏览0评论

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

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

Share Improve this question edited Dec 20, 2019 at 8:36 Liiuc 1821 silver badge13 bronze badges asked Dec 20, 2019 at 8:31 PadavanPadavan 1032 silver badges10 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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

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

Another way you can map the states like,

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

Refer Binding-helpers-with-namespace

The following code should help you on your way to only get the state you actually wants, instead of all of the states on the store.

From this approach, it means that you should have your store attached to Vue already, but i guess you already have from the code you're showing.

You might have to swap 'general' with 'modules/general'

puted: {
  ...mapState('general', {
    info: state => state.info
  })
}
发布评论

评论列表(0)

  1. 暂无评论