admin管理员组文章数量:1385016
I'm using Vue3
and Vuex4
, I keep getting the error:
Uncaught TypeError: Cannot read properties of undefined (reading 'state')
at ReactiveEffect.eval [as fn] (App.vue?3dfd:36)
at ReactiveEffect.run (reactivity.esm-bundler.js?a1e9:160)
at ComputedRefImpl.get value [as value] (reactivity.esm-bundler.js?a1e9:1087)
at setup (App.vue?3dfd:37)
at callWithErrorHandling (runtime-core.esm-bundler.js?5c40:6656)
at setupStatefulComponent (runtime-core.esm-bundler.js?5c40:6272)
at setupComponent (runtime-core.esm-bundler.js?5c40:6228)
at mountComponent (runtime-core.esm-bundler.js?5c40:4081)
at processComponent (runtime-core.esm-bundler.js?5c40:4056)
at patch (runtime-core.esm-bundler.js?5c40:3651)
I'm trying to set the "hello" to the message variable so I can use it throughout my app, This is my main.js
file:
import { createApp} from 'vue'
import App from './App.vue'
import router from './router'
import { createStore } from 'vuex';
const store = createStore({
state(){
return{
message: 'hello'
}
}
})
createApp(App).use(router, store).mount('#app')
This is my App.vue file, I'm trying to receive it with the position api using the puted function.
import { ref, puted } from 'vue'
import { useStore } from 'vuex'
export default {
name: 'App',
setup(){
const store = useStore();
const message = puted(() => store.state.message);
console.log(message.value);
return{ }
}
}
I'm using Vue3
and Vuex4
, I keep getting the error:
Uncaught TypeError: Cannot read properties of undefined (reading 'state')
at ReactiveEffect.eval [as fn] (App.vue?3dfd:36)
at ReactiveEffect.run (reactivity.esm-bundler.js?a1e9:160)
at ComputedRefImpl.get value [as value] (reactivity.esm-bundler.js?a1e9:1087)
at setup (App.vue?3dfd:37)
at callWithErrorHandling (runtime-core.esm-bundler.js?5c40:6656)
at setupStatefulComponent (runtime-core.esm-bundler.js?5c40:6272)
at setupComponent (runtime-core.esm-bundler.js?5c40:6228)
at mountComponent (runtime-core.esm-bundler.js?5c40:4081)
at processComponent (runtime-core.esm-bundler.js?5c40:4056)
at patch (runtime-core.esm-bundler.js?5c40:3651)
I'm trying to set the "hello" to the message variable so I can use it throughout my app, This is my main.js
file:
import { createApp} from 'vue'
import App from './App.vue'
import router from './router'
import { createStore } from 'vuex';
const store = createStore({
state(){
return{
message: 'hello'
}
}
})
createApp(App).use(router, store).mount('#app')
This is my App.vue file, I'm trying to receive it with the position api using the puted function.
import { ref, puted } from 'vue'
import { useStore } from 'vuex'
export default {
name: 'App',
setup(){
const store = useStore();
const message = puted(() => store.state.message);
console.log(message.value);
return{ }
}
}
Share
Improve this question
edited May 23, 2022 at 7:41
Nikola Pavicevic
23.5k9 gold badges29 silver badges51 bronze badges
asked Oct 8, 2021 at 21:16
Jason GrebJason Greb
673 silver badges7 bronze badges
1 Answer
Reset to default 6Try with:
createApp(App)
.use(router)
.use(store)
.mount('#app')
本文标签: javascriptVuex4Cannot read properties of undefined (reading 39state39)Stack Overflow
版权声明:本文标题:javascript - Vuex4 - Cannot read properties of undefined (reading 'state') - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744532340a2611109.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论