vue string to boolean

There are 2 ways to convert variables to a boolean. The above code is kind of messy and a bit long just to check if our string is “true” or not. This makes absolutely no sense and your code will confuse the hell out of anybody who needs to maintain it (including probably yourself).Just to illustrate what is wrong here, javascript has a very simple set of rules to define how variables are cast when doing loose equality checking (==) [1]. CJ J. Behaviour Description Type Default; time.nearestIfDisabled: If true, it will select the nearest available hour in the timepicker, if the current selected hour is disabled.Per example, if the hour is 12 but all the hours have been disabled until 14, then the 14 will be selected by default. It is easy to convert anything a boolean in JavaScript. a value that evalutes to false–0, undefined, an empty string, null, etc). This is much simpler and easier to understand:Nice. But new Boolean(str) is an object. When you create a new Boolean object from a string, it doesn’t try to check whether the string equals “true” or “false”. We can do it this way:Wonderful, it looks like our problem is solved! 提示错误为type check failed for prop "XXX". Let’s see if we can’t clean it up a bit:Ahh, nice and clean. I was wondering why it wasn’t working, but this makes perfect sense. (note: the parentheses are just there for clarity–if you don’t like them or you’re extra extra concerned about line length, removing them won’t cause any errors).I wrote a script to parse boolean “style” parameters: Why not remove a few of those non-string case conditions by just saying “value = value.toString()” on the first line of the function?do you see value in casting myString to lower so it is a little more robust?myString = (myString.toLowerCase() == “true”);Well, yes, that’s technically an improvement, although very slight. --> < blog-post is-published >

vue string to boolean