Vue.Js if else in view


Vue.Js if else in viewSometimes we need to add if else condition in view. We can use v-if to show the template based on if condition.


Vue.Js if else in view Example

You can add if condition for template simply as below –

Vue.Js if else in view Example:

<script>
new Vue({
    el: "#mainDiv",
    template: '<div v-if="name"><span v-text="name"></span></div>',
    data: {
       name: "John"
    } 
});
</script>
<div id="mainDiv></div>

Advertisements

Add Comment

📖 Read More