Skip to content
Advertisement

How to add dynamically attribute in VueJs

I’m using vuejs and I wanna know how to have control on inputs (add disabled attribute when necessary). Is there any way to add dynamically attribute in vuejs ? Below my Textfield component :

JavaScript

Usage :

JavaScript

Advertisement

Answer

You can bind it to a variable using v-bind:disabled="foo" or :disabled="foo" for short:

JavaScript

Then in Vue you can just set this.myVar = true and it will disable the input.

Edit: add this to your template:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement