search

Home  >  Q&A  >  body text

vuex neutron component cannot call public state - Stack Overflow

I just got into the trap recently and just wanted to try using vuex, but I installed vuex and set a public state in store.js

state: {
        sideBarOpened: false
        //放置公用状态
    }

, in main.js

import Vuex from 'vuex'
import store from './store/store'
Vue.use(Vuex)

But I am in a child component

this.hotSeen=this.$store.state.sideBarOpened;

But it told me that this status is undefined. What steps am I missing?

迷茫迷茫2752 days ago650

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-17 09:58:39

    通过mapGetters
    import { mapGetters } from 'vuex'
    computed: ...mapGetters(['sideBarOpened']),

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-17 09:58:39

    Have you done the registration operation of vuex store, for example:

    const store = new Vuex.Store({
        state: state
        ...
    })
    

    If you have already registered and still have problems, you can try the solution above.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-17 09:58:39

    Is your main.js not injected into the store?

    reply
    0
  • Cancelreply