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

169
Visualizações
Ref property in Nuxt is not getting updated

I have been working with the latest version of Nuxt.js, Nuxt3. I am using the fetch API to get JSON data and use that to make another request. Here is my <script setup> code:

<script setup>
// [...]
const borderNames = ref([])

const { data } = await useAsyncData(countryName, async () => {
  // 1st network call
  const response = (await $fetch(`https://restcountries.com/v3.1/name/${countryName}`))[0]

  response.borders.forEach(async border => {
    // 2nd network call
    const borderRes = (await $fetch(`https://restcountries.com/v3/alpha/${border}`))[0]

    // updating the value of Ref<BorderName[]>
    borderNames.value = [...borderNames.value, borderRes.name.common]
    console.log(borderNames.value)
  })
  return response
})
</script>

<template>
  <!-- [...] -->
  <span>Borders: {{ borderNames }}</span>
</template>

The console gives the following output, proving that the network call is working as expected and the Ref value is updated accordingly:

> [ 'Germany' ]
> [ 'Germany', 'Netherlands' ]
> [ 'Germany', 'Netherlands', 'Luxembourg' ]
> [ 'Germany', 'Netherlands', 'Luxembourg', 'France' ]

But on the website, I get an empty array, Borders: []. Why isn't the value of borderNames updated the DOM?

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