Today marks my inaugural use of the openweather.com API for weather forecasts. My goal is to display specific information for the upcoming 5 days:
- Minimum and Maximum temperature for each day
- Weather icon
- Current weather description (Drizzle, Sunny...)
Keeping it simple and straightforward, but I seem to be encountering some rather odd outcomes. Please refer to the image below for better clarity (I suspect that these five results are from the same day, just at different timestamps due to the min/max temperature details...)
https://i.sstatic.net/8AdNm.jpg
Here's the code snippet I'm working with:
async getForecast()
{
let url = "https://api.openweathermap.org/data/2.5/forecast";
let payload =
{
lat: this.$app.globals.origin.lat,
lon: this.$app.globals.origin.lng,
units: 'metric',
APPID: '0feb06072d87320932559f321ca221fb',
lang:'es',
cnt:5
};
let response = await axios.get(url, { params: payload });
this.data = response.data.list;
}
Incorporating it into my Vue.js view:
<div style="width:auto; height:100%; display:flex; align-items:center;">
<a style="width:auto; padding:10; height:100%; display:flex; flex-direction:column; align-items:center; justify-content:space-around;" v-for="(item,index) in data" :key="index">
<span class="fs_smaller c_normal">{{ item.main.temp_min }} / {{ item.main.temp_max }}</span>
<span class="fs_smaller c_normal">{{ item.weather[0].description }}</span>
<img style="width:50px; height:auto;" :src="'https://openweathermap.org/img/w/'+item.weather[0].icon+'.png'">
</a>
</div>