Session 4
This commit is contained in:
1 parent
65869fbe87
commit
f4babc01a9
9 files changed
+483
No files matched your search
@@ -0,0 +1,89 @@
|
||||
const app = Vue.createApp({
|
||||
data() {
|
||||
return {
|
||||
contacts: [
|
||||
{ name: "Hans", firstname: "Meier", dateOfBirth: "1967-12-15" },
|
||||
{ name: "Luca", firstname: "Rudolf", dateOfBirth: "1999-01-12" },
|
||||
{ name: "Laura", firstname: "Steiner", dateOfBirth: "2002-12-24" },
|
||||
{ name: "Alfred", firstname: "Hauser", dateOfBirth: "1932-05-16" },
|
||||
],
|
||||
amountOfContacts: 4,
|
||||
isVisible: false,
|
||||
|
||||
name: "",
|
||||
firstname: "",
|
||||
dateOfBirth: "",
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
addContact() {
|
||||
// Das folgende IF verhindert das Hinzufügen eines nicht kompletten Eintrags.
|
||||
if (
|
||||
this.name !== "" &&
|
||||
this.firstname !== "" &&
|
||||
this.dateOfBirth !== ""
|
||||
) {
|
||||
// Kontakt hinzufügen
|
||||
this.contacts.push({
|
||||
name: this.name,
|
||||
firstname: this.firstname,
|
||||
dateOfBirth: this.dateOfBirth,
|
||||
});
|
||||
// Kontaktzähler(amountOfContacts) erhöhen
|
||||
this.amountOfContacts = this.amountOfContacts + 1; // (3 mal das gleiche Resultat)
|
||||
//this.amountOfContacts += 1; // (3 mal das gleiche Resultat)
|
||||
//this.amountOfContacts++ // (3 mal das gleiche Resultat)
|
||||
|
||||
// Eingaben leeren
|
||||
this.name = "";
|
||||
this.firstname = "";
|
||||
this.dateOfBirth = "";
|
||||
}
|
||||
},
|
||||
},
|
||||
computed: {},
|
||||
// mache einen watcher der uns mitteilt wenn wir 10 oder mehr contacts haben.
|
||||
watch: {
|
||||
/*
|
||||
// für einen spezifischen verbotenen Namen
|
||||
firstname() {
|
||||
// wir wollen keine asdf* in unserer Adressliste
|
||||
// * das ist einfach ein Beispiel
|
||||
console.log("im watcher", this.newContactFirstname);
|
||||
|
||||
// wenn der firstname "asdf" ist soll eine Meldung (alert) kommen, das das keine gültige Eingabe ist.
|
||||
if (this.firstname === "asdf") {
|
||||
alert("dich wollen wir hier nicht");
|
||||
}
|
||||
},
|
||||
*/
|
||||
|
||||
// wir wollen einen Fluchwortfilter beim Vornamen. Egal ob gross oder klein geschrieben
|
||||
firstname() {
|
||||
// verbotene Namen sind: ["marc", "andrea", "yaren", "stefanie", "stephanie", "stefani"]
|
||||
const evils = [
|
||||
"andrea",
|
||||
"marc",
|
||||
"stefani",
|
||||
"stefanie",
|
||||
"stephanie",
|
||||
"yaren",
|
||||
];
|
||||
|
||||
for (let i = 0; i < evils.length; i++) {
|
||||
const evil = evils[i];
|
||||
if (this.firstname === evil) {
|
||||
alert("gtfo");
|
||||
}
|
||||
}
|
||||
},
|
||||
amountOfContacts() {
|
||||
// wenn wir 7 oder mehr kontakte haben soll eine meldung(Zu oberst auf der Seite soll stehen "you're famous") erscheinen.
|
||||
if (this.amountOfContacts >= 7) {
|
||||
this.isVisible = true;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
app.mount("#app");
|
||||
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>TITLE</title>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Jost:wght@400;700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<script src="https://unpkg.com/vue@next" defer></script>
|
||||
<script src="app.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<section id="app">
|
||||
<p v-if="isVisible">YOU'RE FAMOUS</p>
|
||||
<section>
|
||||
Name:<input type="text" v-model="name" /><br />
|
||||
Firstname:<input type="text" v-model="firstname" /><br />
|
||||
Date of Birth<input type="date" v-model="dateOfBirth" /><br />
|
||||
<button @click="addContact">Add to my contacts</button>
|
||||
</section>
|
||||
<p v-for="contact in contacts">
|
||||
{{contact.firstname}}, {{contact.name}}<br />
|
||||
{{contact.dateOfBirth}}
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,64 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
font-family: 'Jost', sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
section {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
|
||||
margin: 3rem;
|
||||
border-radius: 10px;
|
||||
padding: 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 2rem;
|
||||
border-bottom: 4px solid #ccc;
|
||||
color: #970076;
|
||||
margin: 0 0 1rem 0;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1.25rem;
|
||||
font-weight: bold;
|
||||
background-color: #970076;
|
||||
padding: 0.5rem;
|
||||
color: white;
|
||||
border-radius: 25px;
|
||||
}
|
||||
|
||||
input {
|
||||
font: inherit;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
outline: none;
|
||||
border-color: #1b995e;
|
||||
background-color: #d7fdeb;
|
||||
}
|
||||
|
||||
button {
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
border: 1px solid #ff0077;
|
||||
background-color: #ff0077;
|
||||
color: white;
|
||||
padding: 0.05rem 1rem;
|
||||
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.26);
|
||||
}
|
||||
|
||||
button:hover,
|
||||
button:active {
|
||||
background-color: #ec3169;
|
||||
border-color: #ec3169;
|
||||
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.26);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user