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?
淡淡烟草味2017-05-17 09:58:39
通过mapGetters
import { mapGetters } from 'vuex'
computed: ...mapGetters(['sideBarOpened']),
淡淡烟草味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.