lesson 32: dynamic styling

This commit is contained in:
Andreas Zweili 2021-01-18 22:36:41 +01:00
parent 99be089ede
commit 5af511bc87
2 changed files with 26 additions and 3 deletions

View File

@ -1 +1,24 @@
"use strict";
const app = Vue.createApp({
data() {
return {
boxASelected: false,
boxBSelected: false,
boxCSelected: false,
};
},
methods: {
boxSelected(box) {
if (box === "A") {
this.boxASelected = true;
} else if (box === "B") {
this.boxBSelected = true;
} else if (box === "C") {
this.boxCSelected = true;
}
},
},
});
app.mount("#styling");

View File

@ -16,9 +16,9 @@
<h1>Vue Dynamic Styling</h1>
</header>
<section id="styling">
<div class="demo"></div>
<div class="demo"></div>
<div class="demo"></div>
<div class="demo" :style="{borderColor: boxASelected ? 'red' : '#ccc'}" @click="boxSelected('A')"></div>
<div class="demo" @click="boxSelected('B')"></div>
<div class="demo" @click="boxSelected('C')"></div>
</section>
</body>