admin管理员组文章数量:1405311
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 badges2 Answers
Reset to default 7Try 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
})
}
本文标签: javascriptHow to Map subState in nuxtjsStack Overflow
版权声明:本文标题:javascript - How to Map sub-State in nuxtjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744242817a2596869.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论