-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic_styling.html
67 lines (64 loc) · 1.44 KB
/
dynamic_styling.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>VueJS</title>
<script src="vue.js"></script>
<style type="text/css">
.demo {
width: 100px;
height: 100px;
background-color: gray;
display: inline-block;
margin: 10px;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
</style>
</head>
<body>
<div id="app">
<dir class="demo" @click="attachRed = !attachRed" :class="divClasses"></dir>
<dir class="demo" :class="{red: attachRed}"></dir>
<dir class="demo" :class="[color, {red: attachRed}]"></dir>
<dir class="demo" :style="{backgroundColor: color}"></dir>
<dir class="demo" :style="myStyle"></dir>
<dir class="demo" :style="[myStyle, {height: width + 'px'}]"></dir>
<hr>
<input type="text" v-model="color">
<input type="text" v-model="width">
</div>
<script>
new Vue({
el: "#app",
data: {
attachRed: false,
color: 'green',
width: 100
},
computed: {
divClasses() {
return {
red: this.attachRed,
blue: !this.attachRed
};
},
myStyle() {
return {
backgroundColor: this.color,
width: this.width + 'px'
};
}
}
});
</script>
</body>
</html>