vuex neutron component cannot call public state - Stack Overflow
迷茫
迷茫 2017-05-17 09:56:39
0
3
654

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?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
淡淡烟草味

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

淡淡烟草味

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.

淡淡烟草味

Is your main.js not injected into the store?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template