Home  >  Q&A  >  body text

javascript - Modules in vuex output state, but cannot be output on the page?

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

伊谢尔伦伊谢尔伦2735 days ago752

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-18 11:01:03

    Yoursa.js没有导入吧?因为你的new Vuex.Store中,只有globalNumber, so the other one cannot be displayed first

    reply
    0
  • Cancelreply