• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

163
Vistas
Vuex4 - Cannot read properties of undefined (reading 'state')

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 composition api using the computed function.

import { ref, computed } from 'vue'
import { useStore } from 'vuex'

export default {
  name: 'App',
  setup(){
    const store = useStore();

    const message = computed(() => store.state.message);
    console.log(message.value);

    return{ }
  }
}

almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try with:

createApp(App)
  .use(router)
  .use(store)
  .mount('#app')
almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda