показывает
Moscow
Температура: -13°--9° C
Описание: broken clouds
Weather Icon
Ulan-Ude
Температура: -19°--19° C
Описание: smoke
Weather Icon
Seoul
Температура: +5°-+7° C
Описание: few clouds
WeatherCard.vue
<template>
<div class="weather-card">
<h2>{{ name }}</h2>
<p v-if="temperatureMin !== null && temperatureMax !== null">
Температура: {{ formatTemperature(temperatureMin) }}°-{{ formatTemperature(temperatureMax) }}° {{ unit }}
</p>
<p v-else>Температура недоступна</p>
<p>Описание: {{ description }}</p>
<img :src="getWeatherIconUrl(icon)" alt="Weather Icon" class="weather-icon">
</div>
</template>
<script>
export default {
props: {
name: String,
temperatureMin: Number,
temperatureMax: Number,
description: String,
icon: String,
unit: String,
},
methods: {
formatTemperature(temperature) {
if (temperature !== null && typeof temperature === 'number') {
const roundedTemp = Math.round(temperature);
return `${roundedTemp >= 0 ? '+' : ''}${roundedTemp}`;
} else {
return "Недоступно";
}
},
getWeatherIconUrl(icon) {
if (icon && icon !== "") {
return `http://openweathermap.org/img/w/${icon}.png`;
} else {
return 'http://openweathermap.org/img/w/unknown.png';
}
},
},
};
</script>
<style scoped>
.weather-card {
border: 1px solid #ccc;
padding: 10px;
margin: 10px;
width: 200px;
text-align: left;
display: inline-block;
}
.weather-icon {
max-width: 50px;
}
</style>