[Vuejs]-How to display input input fields on condition in VueJs

1👍

Please reference for Vue v-if, v-show https://v2.vuejs.org/v2/guide/conditional.html

<div id="codeTest">
    <input v-show="value == 1" id="input1" type="text" />
    <input v-show="value == 2" id="input2" type="text" />

    {{$data}}
</div>

<script type="text/javascript">
 var inputVM= new Vue({
     el:"#codeTest",
     data: function() {
         return {
             value: 1
         }
     },
     created: function(){
         this.getValueFromDatabase();
     },
     methods: {
         getValueFromDatabase: function() {
            const valueData = callApiMethod(); // not defined
            this.value = valueData // 1 or 2
         }
     }
 })
 </script> 
👤1Rhino

Leave a comment