gpt4 book ai didi

javascript - [Vue 警告] : Error in render: "TypeError: undefined is not an object (evaluating ' this. $store.state')"

转载 作者:行者123 更新时间:2023-12-03 01:51:47 26 4
gpt4 key购买 nike

当我使用 vuex 项目运行 vue 时,出现以下错误。

[Vue warn]: Error in render: "TypeError: undefined is not an object (evaluating '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_datathis.$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,为什么还是出现这个问题?

最佳答案

在 main.js 中更改

import store from './vuex/store.js' 

import {store} from './vuex/store.js' 

关于javascript - [Vue 警告] : Error in render: "TypeError: undefined is not an object (evaluating ' this. $store.state')",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50388674/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com