by Sai gowtham

How to disable Input conditionally in Vue.js

This example shows you how to disable the input box conditionally in vue.js.

<template>
  <div id="app">
    <input type="text" :disabled="disabled" v-model="text">    <button @click="disabled=!disabled">Toggle Enable</button>  </div>
</template>

<script>
export default {
  data() {
    return {
      text: "",
      disabled: false    };
  }
};
</script>

Explanation

We can disable the input box by passing a boolean value true.

In the above code we have passed disabled property to the input disabled attribute by using the Toggle button we are the changing the disabled property value to true.

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course