forked from jigneshbhimani/VueJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4ConditionalRendering(v-if and v-else).txt
102 lines (86 loc) · 3.13 KB
/
4ConditionalRendering(v-if and v-else).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
101
102
define data function
use if directive
make button and apply conditional with button Click
how to use else if
1) How to use v-if?
- src/components/Home.vue:
<template>
<div>
<h1 v-if="show">Conditional Rendering v-if</h1> // add v-if="show"
</div>
</template>
<script>
export default {
name: 'Home',
data(){
return {
show:true // if true then show Conditional Rendering, if false then not show Conditional Rendering
}
}
}
</script>
2) How to use v-if and v-else together?
- src/components/Home.vue:
<template>
<div>
<h1 v-if="show">Conditional Rendering v-if</h1>
<h1 v-else>Conditional Rendering v-else</h1> // add v-else
</div>
</template>
<script>
export default {
name: 'Home',
data(){
return {
show:true // if false then show Conditional Rendering v-else line, if true then show Conditional Rendering v-if line
}
}
}
</script>
3) How to use with Button Click with v-if?
- src/components/Home.vue:
<template>
<div>
<h1 v-if="show">Conditional Rendering v-if</h1>
<button>Toggle Element</button> // add this line
</div>
</template>
<script>
export default {
name: 'Home',
data(){
return {
show:true
}
},
methods:{
display(){
this.show = !this.show; // If I can click Toggle Element then show Conditional Rendering v-if, again i click then hide Conditional Rendering v-if
}
}
}
</script>
4) How to use with Button Click with v-if and v-else?
- src/components/Home.vue:
<template>
<div>
<h1 v-if="show">Conditional Rendering v-if</h1>
<h1 v-else>Conditional Rendering v-else</h1>
<button>Toggle Element</button> // add this line
</div>
</template>
<script>
export default {
name: 'Home',
data(){
return {
show:true
}
},
methods:{
display(){
this.show = !this.show; // If I can click Toggle Element then show Conditional Rendering v-if, again i click then show Conditional Rendering v-else
}
}
}
</script>