问题描述
使用namespace的store使用mapState获取state为undefined
解决方案
1....mapState中基于属性的访问
...mapState({
searchInput: state => state.yourModuleName.searchInput,
})
2.在Vuex模块中使用namespace
..........
modules: {
yourModuleName: {
namespaced: true,
.........
/* Using the namespace in mapState */
...mapState('yourModuleName',[
'searchInput',
])
OR
computed: mapState('ModuleName',[
'state'
])
参考文章
Vuex map state undefined state