store.js
export default new Vuex.Store({
state:{
globalNumber:0
},
modules:[a]
});
a.js
const state={
alocalNumber:0
}
export default {
state
}
a.vue
<template>
<p>
{{global}} -- {{local}}
</p>
</template>
<script>
import { mapState } from "vuex";
import type from "../../store/type.js"
export default {
computed:{
/*
local(){
return this.$store.state.a.alocalNumber
},
*/ //如果按照return this.$store.state.a.alocalNumber也可以显示。
...mapState({
alocal:"alocalNumber", //这个不显示
global:"globalNumber" //这个可以显示
}),
}
}
</script>
mapState What is the use of this method? Is it invalid in modules? Please advise, thank you
Yours
a.js
没有导入吧?因为你的new Vuex.Store中,只有globalNumber
, so the other one cannot be displayed first