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

287
Vistas
VueX, NuxtJs. Trying to store data inside state, sets empty array instead of correct data

I'm trying to set mutated data from an API inside of the state, the problem is that instead of the data it sets an empty array inside of my state. If I console.log state.user.typeSortedModuleItems, it displays the correct data that should be set. But somehow it sets state.user.typeSortedModuleItems to an empty array when I check Vue.js Devtools.

This is the store action, from here I get the data from the API, the response data goes to setTypeSortedModuleItems.

async getTypeSortedModuleItems({commit}, data) {
let token = localStorage.getItem('authToken')
let urlParams = '?' + qs.stringify(data)
try {
  await Api().get('/url/to/api' + urlParams,
    {
      headers: {
        'Accept': 'application/json',
        'Authorization': token
      }
    })
    .then(response => {

      commit('setTypeSortedModuleItems', response.data)
    })
    .catch( (error) => {
      if (error.response) {
        console.log(error.response.data)
        console.log(error.response.headers)
      } else if (error.request) {
        console.log(error.request)
        console.log(error.message)
      } else {
        console.log('Error', error.message)
      }
    })
} catch (err) {
  console.log(err.messages)
}

}

Here I mutate de data and store it to the state, when I console.log 'typeSortedModuleItems' and 'state.user.typeSortedModuleItems' it shows the correct data, but the state doesn't update.

setTypeSortedModuleItems(state, list) {

let typeSortedModuleItems = []

if (list !== null) {
  for (let i = 0; i < list.length; i++) {
    let moduleType = list[i].ModuleTypeDescription

    if (typeSortedModuleItems[moduleType]) {
      typeSortedModuleItems[moduleType].push(list[i])
    } else {
      typeSortedModuleItems[moduleType] = [list[i]]
    }
  }
} else {
  console.log(list)
}
console.log(typeSortedModuleItems)
state.user.typeSortedModuleItems = typeSortedModuleItems
console.log(state.user.typeSortedModuleItems)

}

here's a screenshot of the console end vue devtools. screenshot of the console end vue devtools

I have no idea whats going wrong here, or if the thing i'm trying to do is even possible. I hope for some help/advice. Thanks!

about 4 years ago · Juan Pablo Isaza
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