-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path8Class&StyleBindings.txt
119 lines (85 loc) · 3.26 KB
/
8Class&StyleBindings.txt
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
Class and Style Bindings
- How to use class
- How to use style
- Class and style with object
- Class and style with array
- Class with condition
- Style with property
1) How to use class and style?
- src/components/Home.vue:
<template>
<div>
<h1 class="homestyle">Class and Style Bindings</h1> // add this line
<h1 v-bind:style="{{color:'blue}}">Style Bindings</h1> // add this line
</div>
</template>
<script>
export default {
name: 'Home',
}
</script>
<style scoped>
.homestyle{ // add this style
color: orange;
}
</style>
2) How to use class binding with object?
- src/components/Home.vue:
<template>
<div>
<h1 class="homestyle">Class and Style Bindings</h1>
<h1 v-bind:style="{{color:'blue}}">Style Bindings</h1>
<h1 v-bind:class="{display:show,displayColor:show}">Class Binding with Object</h1> // If {display:true} than console me class create hoga, If {display:show} then console me class create nahi hoga
</div>
</template>
<script>
export default {
name: 'Home',
data(){
return {
show:true // if show:true then show brown color, otherwise show:false then don't show brown color
}
}
}
</script>
<style scoped>
.homestyle{ // add this style
color: orange;
}
.display{
background-color:brown;
}
</style>
3) How to use class binding with array?
- src/components/Home.vue:
<template>
<div>
<h1 class="homestyle">Class and Style Bindings</h1>
<h1 v-bind:style="{{color:colorKey}}">Style Bindings</h1>
<h1 v-bind:class="{display:show,displayColor:show}">Class Binding with Object</h1>
<h1 v-bind:class="[aclass]">Class Binding with Array</h1> // array ma levanu
</div>
</template>
<script>
export default {
name: 'Home',
data(){
return {
show:true,
aclass: 'arrayClass', // As a property define karvu padse
colorKey: 'red'
}
}
}
</script>
<style scoped>
.homestyle{
color: orange;
}
.display{
background-color:brown;
}
.arrayClass{ // add this style
background-color: cyan;
}
</style>