How to disable input conditionally in vue.js

后端 未结 11 1261
余生分开走
余生分开走 2020-12-07 10:11

I have an input:



        
11条回答
  •  误落风尘
    2020-12-07 10:30

    Your disabled attribute requires a boolean value:

    Notice how i've only checked if validated - This should work as 0 is falsey ...e.g

    0 is considered to be false in JS (like undefined or null)

    1 is in fact considered to be true

    To be extra careful try:

    This double negation turns the falsey or truthy value of 0 or 1 to false or true

    don't believe me? go into your console and type !!0 or !!1 :-)

    Also, to make sure your number 1 or 0 are definitely coming through as a Number and not the String '1' or '0' pre-pend the value you are checking with a + e.g this turns a string of a number into a Number e.g

    +1 = 1 +'1' = 1 Like David Morrow said above you could put your conditional logic into a method - this gives you more readable code - just return out of the method the condition you wish to check.

提交回复
热议问题