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

167
Vistas
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 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