Vue Js If Else Conditionally Example Tutorial

Bootstrap 4 , Html , Css , Vue.Js

Nicesnippets

284

24-07-2020


Vue Js If Else Conditionally Example Tutorial

Hi Guys,

In this tutorial, I will explain you how to use if else conditionally in vue js. I show else conditionally example in vue js. The directive v-if is used to conditionally render a block. The block will only be rendered if the directive’s expression returns a truthy value.and You can use the v-else directive to indicate an “else block” for v-if

Example

<!DOCTYPE html>

<html>

<head>

<title>Vue Js If Else Conditionally Example</title>

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.0-alpha1/css/bootstrap.min.css">

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>

<body class="bg-dark">

<div class="container">

<div class="col-md-6 offset-md-3">

<div class="card mt-5">

<div class="card-header">

<h5 v-bind:class="red">Vue Js If Else Conditionally Example</h5>

</div>

<div class="card-body">

<div class="row">

<div class="col-md-12">

<div v-if="show">

<span class="bg-success p-1 text-white">This is show.</span>

</div>

<div v-else>

<span class="bg-danger p-1 text-white">This is not show.</span>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.min.js"></script>

<script>

Vue.config.devtools = true

var app = new Vue({

el:'.card-body',

data:{

show: true,

}

})

</script>

</body>

</html>

It will help you...


Recommended Posts