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

245
Visualizações
How can use await/async in vue mounted

I am trying to use mapGetters value in my other computed property. It showing null because the preferences method not executed completed. I want to wait until the store set the getter and setter. I am tried async/await but it's not working

mounted() {
  this.preferences();
  this.selectedColumnsHeader;
},

methods: {
  async preferences() {
    await this.$store.dispatch('fetchPreferences');
  }
}

store

fetchPreferences({ commit }) {
  return http
    .get('/help_ticket_preferences.json')
    .then((res) => {
      commit('setPreferences', res.data.preference);
    })
    .catch((error) => {
      commit('setErrorMessage', `Sorry, there was an error fetching help ticket preferences ${error.message}.`);
    });
},
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Firstly, you need to await for this.preferences() in mounted

async mounted() {
  await this.preferences();
  this.selectedColumnsHeader;
},

secondly, you need to return a Promise in fetchPreferences

fetchPreferences({ commit }) {
  return http
    .get('/help_ticket_preferences.json')
    ..... etc

Hoe that helps

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