add my solution for assignment 4
This commit is contained in:
parent
8933709313
commit
0b6020d18d
|
@ -0,0 +1,46 @@
|
|||
"use strict";
|
||||
|
||||
const app = Vue.createApp({
|
||||
data() {
|
||||
return {
|
||||
user1: false,
|
||||
user2: false,
|
||||
paragraphVisible: true,
|
||||
paragraphHidden: false,
|
||||
inputColor: "",
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
classFromUserInput() {
|
||||
return {
|
||||
user1: this.user1,
|
||||
user2: this.user2,
|
||||
visible: this.paragraphVisible,
|
||||
hidden: this.paragraphHidden,
|
||||
};
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getUserInput(event) {
|
||||
const inputValue = event.target.value;
|
||||
if (inputValue === "user1") {
|
||||
this.user1 = true;
|
||||
} else if (inputValue === "user2") {
|
||||
this.user2 = true;
|
||||
} else {
|
||||
this.user1 = false;
|
||||
this.user2 = false;
|
||||
}
|
||||
},
|
||||
toggleParagraphVisibility() {
|
||||
this.paragraphVisible = !this.paragraphVisible;
|
||||
this.paragraphHidden = !this.paragraphHidden;
|
||||
},
|
||||
setBackgroundColor(event) {
|
||||
console.log(event.target.value);
|
||||
this.inputColor = event.target.value;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
app.mount("#assignment");
|
|
@ -1,36 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vue Basics</title>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Jost:wght@400;700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<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>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<h1>Vue Styling</h1>
|
||||
<h1>Vue Styling</h1>
|
||||
</header>
|
||||
<section id="assignment">
|
||||
<!-- 1) Fetch the user input and use it as a CSS class -->
|
||||
<!-- The entered class should be added to the below paragraph -->
|
||||
<input type="text" />
|
||||
<!-- (available classes: "user1", "user2") -->
|
||||
<p>
|
||||
Style me!
|
||||
</p>
|
||||
<button>Toggle Paragraph</button>
|
||||
<!-- 2) Use the "visible" and "hidden" classes to show/ hide the above paragraph -->
|
||||
<!-- Clicking the button should toggle between the two options -->
|
||||
<!-- 1) Fetch the user input and use it as a CSS class -->
|
||||
<!-- The entered class should be added to the below paragraph -->
|
||||
<input type="text" @input="getUserInput" />
|
||||
<!-- (available classes: "user1", "user2") -->
|
||||
<p :class="classFromUserInput">
|
||||
Style me!
|
||||
</p>
|
||||
<button @click="toggleParagraphVisibility">Toggle Paragraph</button>
|
||||
<!-- 2) Use the "visible" and "hidden" classes to show/ hide the above paragraph -->
|
||||
<!-- Clicking the button should toggle between the two options -->
|
||||
|
||||
<!-- 3) Add dynamic inline styling to the below paragraph and let the user enter a background-color -->
|
||||
<input type="text" />
|
||||
<p>Style me inline!</p>
|
||||
<!-- 3) Add dynamic inline styling to the below paragraph and let the user enter a background-color -->
|
||||
<input type="text" @input="setBackgroundColor" />
|
||||
<p :style="{backgroundColor: inputColor}">Style me inline!</p>
|
||||
</section>
|
||||
</body>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
Reference in New Issue