admin管理员组文章数量:1419253
In my puted, I have two "loading" states that I want to track. Is there a way to add an alias to the other state with this syntax?
puted: {
...mapState('barcodes', ['barcodes', 'loading', 'pagination']),
...mapState('users', ['user', 'loading']), // add an alias for this "loading"
}
In my puted, I have two "loading" states that I want to track. Is there a way to add an alias to the other state with this syntax?
puted: {
...mapState('barcodes', ['barcodes', 'loading', 'pagination']),
...mapState('users', ['user', 'loading']), // add an alias for this "loading"
}
Share
Improve this question
asked Oct 25, 2021 at 7:39
patrick_starpatrick_star
731 silver badge6 bronze badges
2 Answers
Reset to default 4mapState has supported an object way, something like: (Specific alias for only 1 field)
puted: {
...mapState('barcodes', {
barcodesLoading: state => state.loading,
})
}
Or by namespace: (If you want to wrap all user state into the userData namespace)
puted: {
...mapState({
barcodeData: 'barcodes',
userData: 'users'
})
}
on Template:
<div>{{barcodeData.loading}}</div>
There is another thread for your reference:
vuex namespaced mapState with multiple modules
I'm not absolutely sure, because I can't check it out right now. But AFAIK you should just try this:
puted: {
...mapState('barcodes', {barcodes:'barcodes', alias1:'loading', pagination:'pagination'}),
...mapState('users', {user:'user', alias2:'loading'}), // add an alias for this "loading"
}
I.e. use object instead of array.
本文标签: javascriptRename Vue mapState stateStack Overflow
版权声明:本文标题:javascript - Rename Vue mapState state - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745300925a2652365.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论