VueJS lekcja 4 do dokończenia
This commit is contained in:
1 parent
58990da7c8
commit
b89a51bd40
6 files changed
+480
No files matched your search
@@ -0,0 +1,155 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Lekcja 4</title>
|
||||
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
||||
<style>
|
||||
.progressbar {
|
||||
background-color: darkgray;
|
||||
width: 100%;
|
||||
height: 1rem;
|
||||
}
|
||||
|
||||
.progressbar-inside {
|
||||
background-color: chartreuse;
|
||||
height: 1rem;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.r {
|
||||
width: 50%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app">
|
||||
<h2>02. Forms & Computed</h2>
|
||||
<main>
|
||||
<div class="progressbar">
|
||||
<div class="progressbar-inside" :style="{ width: progressbar_width + '%' }">
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<div class="l">
|
||||
<h2>Uzupełnij dane</h2>
|
||||
<input type="text" @change="update" id="nick" placeholder="nick"><br><br>
|
||||
<input type="number" @change="update" id="age" placeholder="min. 18"><br><br>
|
||||
<input type="text" @change="update" id="prof" placeholder="Specjalizacja"><br><br>
|
||||
<input type="number" @change="update" id="wage" placeholder="Stawka"><br><br>
|
||||
</div>
|
||||
<div class="r">
|
||||
<h2>Podgląd</h2>
|
||||
<p>Pseudonim: {{ nick }}</p>
|
||||
<p>Wiek: {{ age }}</p>
|
||||
<p>Specjalizacja: {{ prof }}</p>
|
||||
<p>Stawka: {{ wage }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button :disabled="btn_disabled" @click="generate_profile">Generuj profil</button>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
const app = Vue.createApp({
|
||||
data() {
|
||||
return {
|
||||
progressbar_width: 0,
|
||||
|
||||
nick_completed: false,
|
||||
age_completed: false,
|
||||
prof_completed: false,
|
||||
wage_completed: false,
|
||||
|
||||
nick: '---',
|
||||
age: '---',
|
||||
prof: '---',
|
||||
wage: '---',
|
||||
|
||||
btn_disabled: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
update(e) {
|
||||
// to z pewnością się da zrobić lepiej
|
||||
switch (e.target.id) {
|
||||
case 'nick':
|
||||
if (e.target.value.length > 2) {
|
||||
this.nick = e.target.value;
|
||||
|
||||
if (!this.nick_completed) { this.progressbar_width += 25; }
|
||||
this.nick_completed = true;
|
||||
} else {
|
||||
this.nick = '---';
|
||||
|
||||
if (this.nick_completed) { this.progressbar_width -= 25; }
|
||||
this.nick_completed = false;
|
||||
}
|
||||
break;
|
||||
case 'age':
|
||||
if (parseInt(e.target.value) >= 18) {
|
||||
this.age = e.target.value;
|
||||
|
||||
if (!this.age_completed) { this.progressbar_width += 25; }
|
||||
this.age_completed = true;
|
||||
} else {
|
||||
this.age = '---';
|
||||
|
||||
if (this.age_completed) { this.progressbar_width -= 25; }
|
||||
this.age_completed = false;
|
||||
}
|
||||
break;
|
||||
case 'prof':
|
||||
if (e.target.value.length > 0) {
|
||||
this.prof = e.target.value;
|
||||
|
||||
if (!this.prof_completed) { this.progressbar_width += 25; }
|
||||
this.prof_completed = true;
|
||||
} else {
|
||||
this.prof = '---';
|
||||
|
||||
if (this.prof_completed) { this.progressbar_width -= 25; }
|
||||
this.prof_completed = false;
|
||||
}
|
||||
break;
|
||||
case 'wage':
|
||||
if (parseInt(e.target.value) > 0) {
|
||||
this.wage = e.target.value;
|
||||
|
||||
if (!this.wage_completed) { this.progressbar_width += 25; }
|
||||
this.wage_completed = true;
|
||||
} else {
|
||||
this.wage = '---';
|
||||
|
||||
if (this.wage_completed) { this.progressbar_width -= 25; }
|
||||
this.wage_completed = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
this.nick_completed &&
|
||||
this.prof_completed &&
|
||||
this.age_completed &&
|
||||
this.wage_completed
|
||||
) {
|
||||
this.btn_disabled = false;
|
||||
}
|
||||
},
|
||||
generate_profile() {
|
||||
alert(`Profil ${this.nick} został utworzony.`);
|
||||
}
|
||||
}
|
||||
}).mount("#app");
|
||||
|
||||
</script>
|
||||
|
||||
</html>
|
||||
Reference in new issue
Block a user