v-else-if Directive in Vue.js
Syntax:
v-else-if="data"
Parameters: This function accepts a single parameter which is data or a condition.
Example 1: This example uses Vue.js to show an element with v-else-if using arithmetic conditions.
<!DOCTYPE html>
<html>
<head>
<title>
VueJS | v-else-if directive
</title>
<!-- Load Vuejs -->
<script src=
"https://cdn.jsdelivr.net/npm/vue/dist/vue.js">
</script>
</head>
<body>
<div style="text-align: center;
width: 600px;">
<h1 style="color: green;">
GeeksforGeeks
</h1>
<b>
VueJS | v-else-if directive
</b>
</div>
<div id="canvas" style=
"border:1px solid #000000;
width: 600px;height: 200px;">
<div id="app">
<h2 v-if="data > 50">
data is greater than 50
</h2>
<h2 v-else-if="data < 50">
data is smaller than 50
</h2>
<h2 v-else>
data is equal to 50
</h2>
</div>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
data: 40
}
})
</script>
</body>
</html>
Output:

<!DOCTYPE html>
<html>
<head>
<title>
VueJS | v-else-if directive
</title>
<!-- Load Vuejs -->
<script src=
"https://cdn.jsdelivr.net/npm/vue/dist/vue.js">
</script>
</head>
<body>
<div style="text-align: center;
width: 600px;">
<h1 style="color: green;">
GeeksforGeeks
</h1>
<b>
VueJS | v-else-if directive
</b>
</div>
<div id="canvas" style=
"border:1px solid #000000;
width: 600px;height: 200px;">
<div id="app">
<h2 v-if="data">
if is executed
</h2>
<h2 v-else-if="!data">
else-if is executed
</h2>
</div>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
data: false
}
})
</script>
</body>
</html>
Output:
