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

I have created a state ~storemodulesgeneralindex.jsThere are get_info and get_pages Actions,states

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
  })
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744242817a4564785.html

相关推荐

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

    I have created a state ~storemodulesgeneralindex.jsThere are get_info and get_pages Actions,states

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信