Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

352
Visualizações
Vuex Data doesn't get updated on fetch when reloading browser (SSR) Nuxt

I found something about this bug I explained at end;

Component codes

  async fetch(){ await this.$store.dispatch('bots/getBots') },
  computed: { ...mapState('bots', ['bots']) },

Store codes

export const state = () => {
  return {
    bots: []
  }
}

export const mutations = {
  UPDATE_BOTS(state, bots) {
    state.bots = bots
  }
}

export const actions = {
  getBots({commit}) {
    this.$axios.$get('url', {headers: {uid: '12345'}})
      .then(res => {
        commit('UPDATE_BOTS',res.robots)
      })
      .catch(e => {
        console.log(e)
      })
  }
}

Issue: When moving between pages via nuxt-link data loads perfectly but when I reload the page bots state is empty...

Found Issue: I use nuxt-auth and I had one plugin for checking status of axios request that if it was 401 unauthorized I logout user if he was loggedIn, So status undefined error was from here but I commented the plugin codes and I got other error from nuxt-auth that causes that problem I had So I related that issue in other question u can see it here: Nuxt-Auth Bug: Looks for autherization in any get request that has headers config

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It is the expected behavior. Vuex state is kept in memory and when you reload the page it gets purged.

about 4 years ago · Juan Pablo Isaza Relatório

0

Instead of this state

export const state = () => {
  return {
    bots: []
  }
}

try this

export const state = () => ({
    bots: []
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda