u need to define store inside vue instance. something like below:
import store from './vuex'
const app = new Vue({
el:'#app',
store: store
})
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey guys,
I am having trouble passing the state to my components. Currently, my files run look this:
-store.js (handling the state)
-services.js (making all API requests)
-component.vue (showing my component)
I access the state in the component like this:
computed: {
...mapState({
dashboard: state => state.dashboard
// this.dashboard returns an Observer Object
}),
getUser: function () {
return this.$store.state.user; //this yields undefined
}
}
and in my store.js, I have:
const state = {
status: {},
user: null //this gets assigned an object with user data
// this object I want to pass to my component
}
//I tried setting a getter but yields undefined
const getters = {
user(state) {
return state.user
}
}
When I console.log(this.dashboard) in my component, I can see the Observer component but I cannot access it.
GOAL: I want to grab the user object in the state and send it to my parent component via props.
TIA
Please or to participate in this conversation.