Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createApp и шаблон погода #3

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 01-basics/10-create-app/script.js
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
import { defineComponent, createApp } from 'vue/dist/vue.esm-bundler.js'

const App = defineComponent({
name: 'App',

setup() {
return {
}
},

template: `
<div>Сегодня ${ new Date().toLocaleDateString(navigator.language, { dateStyle: 'long' }) }</div>
`,
Comment on lines +11 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше такие выражения выносить в вспомогательные функции, чтобы не перегружать шаблон

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо большое, буду иметь ввиду

})

const app = createApp(App)

app.mount('#app')
48 changes: 36 additions & 12 deletions 01-basics/20-weather/WeatherApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,68 @@ import { getWeatherData, WeatherConditionIcons } from './weather.service.ts'
export default defineComponent({
name: 'WeatherApp',

setup() {
function convertNumber(value) {
return value.toFixed(1);
}

function convertMmHg(value) {
return (value * 0.75).toFixed(0);
}

function timeComparison(currentTime, sunriseTime, sunsetTime) {
return currentTime < sunriseTime || currentTime > sunsetTime;
}

return {
convertNumber,
convertMmHg,
timeComparison,
getWeatherData,
WeatherConditionIcons,
}
},

template: `
<div>
<h1 class="title">Погода в Средиземье</h1>

<ul class="weather-list unstyled-list">
<li class="weather-card weather-card--night">
<div class="weather-alert">
<ul v-for="item in getWeatherData()" class="weather-list unstyled-list">
<li class="weather-card"
:class="{ 'weather-card--night' : timeComparison(item.current.dt, item.current.sunrise, item.current.sunset) }"
>
<div v-if="item.alert" class="weather-alert">
<span class="weather-alert__icon">⚠️</span>
<span class="weather-alert__description">Королевская метеослужба короля Арагорна II: Предвещается наступление сильного шторма.</span>
<span class="weather-alert__description">{{ item.alert.sender_name }}: {{ item.alert.description }}</span>
</div>
<div>
<h2 class="weather-card__name">
Гондор
{{ item.geographic_name }}
</h2>
<div class="weather-card__time">
07:17
{{ item.current.dt }}
</div>
</div>
<div class="weather-conditions">
<div class="weather-conditions__icon" title="thunderstorm with heavy rain">⛈️</div>
<div class="weather-conditions__temp">15.0 °C</div>
<div class="weather-conditions__icon" :title="item.current.weather.description">{{ WeatherConditionIcons[item.current.weather.id] }}</div>
<div class="weather-conditions__temp">{{ convertNumber(item.current.temp - 273.15) }} °C</div>
</div>
<div class="weather-details">
<div class="weather-details__item">
<div class="weather-details__item-label">Давление, мм рт. ст.</div>
<div class="weather-details__item-value">754</div>
<div class="weather-details__item-value">{{ convertMmHg(item.current.pressure) }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Влажность, %</div>
<div class="weather-details__item-value">90</div>
<div class="weather-details__item-value">{{ item.current.humidity }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Облачность, %</div>
<div class="weather-details__item-value">100</div>
<div class="weather-details__item-value">{{ item.current.clouds }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Ветер, м/с</div>
<div class="weather-details__item-value">10.5</div>
<div class="weather-details__item-value">{{ item.current.wind_speed }}</div>
</div>
</div>
</li>
Expand Down
Loading