I get the bellow error when I run my vue with vuex project.
[Vue warn]: Error in render: "TypeError: undefined is not an object (evaluating 'this.$store.state')"
in my project, I created the vuex/store.js
:
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export const store = new Vuex.Store({
state:{
user_data: null,
is_login: false
}
});
in my main.js
:
import store from './vuex/store.js'
...
new Vue({
el: '#app',
router,
store,
render: h => h(App)
});
...
in my app.vue:
<template>
<div>
<registration></registration>
<hr>
<registrations></registrations>
</div>
</template>
<script>
import registration from './views/components/registrations/registration.vue'
import registrations from './views/components/registrations/registrations.vue'
export default{
props: {
},
data(){
return {
}
},
components: {
registration,
registrations
}
}
</script>
in my registration.vue
, i used the this.$store.state.user_data
and this.$store.state.is_login
, the error is in there report:
<style scoped>
</style>
<template>
<div style="margin-top: 20px">
<h1>registration</h1>
{{ is_login }}
<hr>
{{ user_data }}
</div>
</template>
<script>
export default{
data(){
return {
msg: 'hello vue'
}
},
computed: {
is_login(){
debugger
return this.$store.state.is_login
},
user_data(){
return this.$store.state.user_data
}
},
components: {}
}
</script>
I have registerd the store
in Vue, why there still get this issue?