当我使用vuex项目运行vue时,我收到了波纹管错误。
[Vue警告]:渲染错误:“TypeError:undefined不是对象(评估'this。$ store.state')”
在我的项目中,我创建了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
}
});
在main.js
:
从'./vuex/store.js'
导入商店...
new Vue({
el: '#app',
router,
store,
render: h => h(App)
});
...
在我的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>
在我的registration.vue
中,我使用了this.$store.state.user_data
和this.$store.state.is_login
,错误出现在报告中:
<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>
我已在Vue注册store
,为什么还会遇到此问题?
答案 0 :(得分:1)
更改
import store from './vuex/store.js'
到
import {store} from './vuex/store.js'