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

275
Visualizações
Nuxt3/Pinia: Computed properties not getting updated

I have a component in which the values are updated from computed properties. I have added a nuxtServerInit plugin to make a fetch call on nuxt app creation and update values. But somehow the fetch promise is resolved after the computed properties is run and the store values at this time is always empty. How can i make sure that my computed properties are updated only after the promise is resolved. Below are the files created:

component.vue

<template>
  <select>
   <div v-for="(data, index) in dataList" :key="index">
    <option :value="data.value">{{ data.label }}</option>
   </div>
  </select>
</template>

<script>
 import { allDataStore } from '@/store/allDataStore.js'

 export default {
  setup(){
   const reqData = allDataStore()

   return {
    reqData
   }
  },
  computed: {
   dataList() {
    console.log('inside computed dataList')
    return this.reqData
   },
  }
 }
</script>

nuxtServerInit.js

import { allDataStore } from '@/store/allDataStore.js'
export default defineNuxtPlugin((nuxtApp) => {
 nuxtApp.hook('app:created', async () => {
    console.log('inside nuxtApp hook')
    const dataFetch = allDataStore()
    await dataFetch.fetchAllData()
 })
})

allDataStore.js

import { defineStore } from 'pinia'
export const masterDataStore = defineStore('masterDataStore', {
 state: () => ({
  allData: {}
 }),
 getters: {
  getReqData: state => state.allData,
 },
 actions: {
  fetchAllData (){
    console.log('inside fetchAllData call')
    const newData = $fetch('url').then(res) => {
    console.log('data received')
     return res[0]
    }
  }
 }
}

Currently the code is running in following order: 'inside nuxtApp hook' -> 'inside fetchAllData call' -> 'inside computed dataList' -> console.log('data received')

But the following order is needed: 'inside nuxtApp hook' -> 'inside fetchAllData call' -> console.log('data received') -> 'inside computed dataList'

about 4 years ago · Santiago Trujillo
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