Home Examples Charts Dashboard Projects Menu

Vue.js examples
Learn Vue.js

Vuejs if

Related course:
Fullstack Vue: The Complete Guide to Vue.js

Show data with an if statement?

Vue.js supports if statements.
If the value of a variable is true, it will be shown. Otherwise, it will be invisible.

v-if example

First define a variable in your Vue app:

new Vue({
el: '#app',
data: {
show: true

Then we add this variable to a div using v-if:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<!-- include vue -->
<script src="//unpkg.com/vue"></script>
<div id="app">
<div v-if="show">
The variable show is set to
<script src="app.js"></script>

If you want to show a div when a variable is set to false, use this instead:

<div v-if="!show">

Note: the exclamation mark (!) negates the case.

← Vue.js for vuejs model →


© vuejsexamples.net - Privacy Policy - Cookie Policy