Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

91
Vistas
How to set / retrieve objects from Vuex state

In the following code snippet, why and how do the state and man return empty while I can still access a property of the man object?

note: The code snippet is a module that is part of a module that is imported into another file in which the store is created.

class Man {
    constructor(firstName, lastName) {
        this.firstName = firstName
        this.lastName = lastName
    }
}

const state = {
    man: undefined,
}

const mutations = {
    setMan(state, data) {
        state.man = new Man(
            data.firstName,
            data.lastName
        )
        console.log("state: " + JSON.stringify(state)) // state: {}
        console.log("man: " + JSON.stringify(state.man)) // man: {}
        console.log("first name: " + state.man.firstName) // John
    }
}


commit('setMan', {
    firstName: "John",
    lastName: "Snow"
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The state, mutations should actually be properties of the store configs. There you declare the properties but they are not wrapped in the Vuex store.

You might want to check this page of the doc that explains it: https://vuex.vuejs.org/guide/#the-simplest-store.

(Here you are missing the createStore part.)

about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda