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

212
Visualizações
Nuxt 3 api call with data from another api call

I am building a weather forecast app and to get data for a specific city i have a dynamic url (/forecast/[id]) with the city id from open-meteo. To get the actual lat and lon I want to make an api call to the open-meteo geocoding api to then use the retrieved lat and lon and timezone to make another request to the open-meteo forecast api. But unfortunately i was unable to make it work.

here is my current code:

<script setup>
const route = useRoute()
const id = route.params.id
const lat = ref(null)
const lon = ref(null)
const timezone = ref("")

const {data: locationdata} = await useAsyncData("geocode", () =>
  $fetch(`https://geocoding-api.open-meteo.com/v1/get?id=${id}`)
).then((res) => {
  lat.value = res.data.value.latitude
  lon.value = res.data.value.longitude
  timezone.value = res.data.value.timezone
})


const { data: weatherdata, pending } = await useAsyncData("weatherdata", () =>
  $fetch(`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&hourly=temperature_2m,relativehumidity_2m,surface_pressure,precipitation,weathercode,windspeed_10m,winddirection_10m,windgusts_10m&current_weather=true&windspeed_unit=kn&timezone=${timezone}`)
).catch((e) => {
  console.log(e)
})
</script>
<template>
<pre><code>{{weatherdata}}</code></pre>
</template>
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