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?
通过mapGetters
import { mapGetters } from 'vuex'
computed: ...mapGetters(['sideBarOpened']),
Have you done the registration operation of vuex store, for example:
If you have already registered and still have problems, you can try the solution above.
Is your main.js not injected into the store?