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,66 @@
|
|||||||
|
<!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>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
<h2>01. Forms</h2>
|
||||||
|
<form action="/send" method="post" @reset="reset" @submit="submit">
|
||||||
|
<input type="text" v-model="content" name="tekst" id="tekst">
|
||||||
|
<input type="reset" value="resetuj">
|
||||||
|
<input type="submit" value="wyślij">
|
||||||
|
<input type="checkbox" v-model="block" id="blokuj"><label for="blokuj">Blokuj działania formularza</label>
|
||||||
|
</form>
|
||||||
|
<h3 id="message">{{ message }}</h3>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h2>Modyfikator @click.prevent na linku</h2>
|
||||||
|
<a href="https://vuejs.org" @click="link_click">Przejdź do Vue.js</a>
|
||||||
|
<input type="checkbox" v-model="blocklink" id="blocklink"><label for="blocklink">Blokada
|
||||||
|
działania linku</label>
|
||||||
|
<h3>{{ msg2 }}</h3>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const app = Vue.createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
message: 'formularz',
|
||||||
|
content: '',
|
||||||
|
block: true,
|
||||||
|
blocklink: true,
|
||||||
|
msg2: 'link'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
submit(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.block ? this.message = 'formularz się nie wysyła' : this.message = 'formularz wysłany';
|
||||||
|
},
|
||||||
|
reset(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!this.block) this.content = '';
|
||||||
|
this.block ? this.message = 'formularz się nie resetuje' : this.message = 'formularz zresetowany';
|
||||||
|
},
|
||||||
|
link_click(e) {
|
||||||
|
if (this.blocklink) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.msg2 = 'działanie linku zostało zablokowane';
|
||||||
|
} else {
|
||||||
|
this.msg2 = 'kliknięto link, następuje przekierowanie';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).mount("#app");
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -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>
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
<!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>
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progressbar {
|
||||||
|
background-color: darkgray;
|
||||||
|
width: 100%;
|
||||||
|
height: 1rem;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progressbar-inside {
|
||||||
|
background-color: chartreuse;
|
||||||
|
height: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flex {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flex>div {
|
||||||
|
width: 33%;
|
||||||
|
margin-left: 0.33%;
|
||||||
|
background-color: darkgray;
|
||||||
|
padding: .5rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
<h2>Koszyk krok po kroku: v-if, v-model, computed, checkbox, radio, range, select</h2>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div class="progressbar">
|
||||||
|
<div class="progressbar-inside" :style="{ width: (step * 34) + '%' }">
|
||||||
|
</div>
|
||||||
|
</div><br>
|
||||||
|
|
||||||
|
<div class="flex">
|
||||||
|
<div>
|
||||||
|
<h2>Krok 1: Wybierz sprzęt</h2>
|
||||||
|
<input type="checkbox" name="sprzet" id="s1" @change="s_change"><label for="s1">Myszka
|
||||||
|
bezprzewodowa</label><br>
|
||||||
|
<input type="checkbox" name="sprzet" id="s2" @change="s_change"><label for="s2">Laptop Dev
|
||||||
|
Edition</label><br>
|
||||||
|
<input type="checkbox" name="sprzet" id="s3" @change="s_change"><label for="s3">Stacja Robocza
|
||||||
|
PC</label><br>
|
||||||
|
|
||||||
|
<p>Liczba zestawów: {{ s_k }}</p>
|
||||||
|
<input type="range" name="zestawy" id="z1" min="1" max="10" v-model="s_k">
|
||||||
|
</div>
|
||||||
|
<div v-if="step > 0">
|
||||||
|
<h2>Krok 2: Forma odbioru</h2>
|
||||||
|
<select v-model="delivery" @change="d_change">
|
||||||
|
<option value="">-- wybierz dostawę --</option>
|
||||||
|
<option>Kurier</option>
|
||||||
|
<option>Poczta</option>
|
||||||
|
<option>Osobiście</option>
|
||||||
|
</select>
|
||||||
|
<p>Sposób dostawy: {{ delivery }}</p>
|
||||||
|
</div>
|
||||||
|
<div v-if="step > 1">
|
||||||
|
<h2>Krok 3: Podsumowanie i zgoda</h2>
|
||||||
|
<input type="checkbox" name="agreement" v-model="agreement" id="agreement"
|
||||||
|
@change="agreement_change"><label for="agreement">Potwierdzam zgodność danych</label>
|
||||||
|
<p>Ilość: {{ s_k }} zestawów</p>
|
||||||
|
<p>Status: {{ status_msg() }}</p>
|
||||||
|
<button :disabled="!agreement" @click="order">Zamów zestaw</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const app = Vue.createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
step: 0,
|
||||||
|
|
||||||
|
s_k: 1,
|
||||||
|
s_checked: 0,
|
||||||
|
|
||||||
|
delivery: '',
|
||||||
|
agreement: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
s_change(e) {
|
||||||
|
if (e.target.checked) {
|
||||||
|
this.s_checked += 1;
|
||||||
|
} else {
|
||||||
|
this.s_checked -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.s_checked > 0) {
|
||||||
|
if (this.step < 2) {
|
||||||
|
this.step = 1;
|
||||||
|
this.d_change();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.step = 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
d_change() {
|
||||||
|
if (this.delivery != '') {
|
||||||
|
this.step = 2;
|
||||||
|
if (this.agreement) {
|
||||||
|
this.step = 3;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.step = 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
agreement_change(e) {
|
||||||
|
this.agreement = e.target.checked;
|
||||||
|
if (this.agreement) {
|
||||||
|
this.step = 3;
|
||||||
|
} else {
|
||||||
|
this.step = 2;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
status_msg() {
|
||||||
|
if (this.agreement) {
|
||||||
|
return 'Gotowe do wysłania!';
|
||||||
|
} else {
|
||||||
|
return 'Zaznacz zgodę';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
order() {
|
||||||
|
alert(`Zamówienie przyjęte!\nIlość: ${this.s_k} zestawów\nDostawa: ${this.delivery}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).mount("#app");
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<!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>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
<input type="text" v-model="str">
|
||||||
|
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
<div v-for="word in word_array()"
|
||||||
|
style="float: left; background-color: lightgray; padding: 1rem; margin: 1rem;">
|
||||||
|
<div v-for="letter in word"
|
||||||
|
style="float: left; font-family: monospace; color: brown; margin: 1rem; background-color: skyblue; padding: 1rem; font-size: 2rem;">
|
||||||
|
{{ letter }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const app = Vue.createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
str: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
word_array() {
|
||||||
|
let str = this.str;
|
||||||
|
let words = str.trim().split(" ");
|
||||||
|
|
||||||
|
for (let i = 0; i < words.length; i++) {
|
||||||
|
words[i] = words[i].split('');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(words)
|
||||||
|
if (words[0].length == 0) { return undefined; }
|
||||||
|
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).mount("#app");
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<!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>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const app = Vue.createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).mount("#app");
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<!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>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const app = Vue.createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).mount("#app");
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
||||||
Reference in new issue
Block a user