In VueJS we can add or remove a DOM element using v-if:
but is there a wa
You don't need because if test is truthy you'll already get the
required
attribute, and if test is falsy you won't get the attribute. The true : false
part is redundant, much like this...
if (condition) {
return true;
} else {
return false;
}
// or this...
return condition ? true : false;
// can *always* be replaced by...
return (condition); // parentheses generally not needed
The simplest way of doing this binding, then, is
Only if the test (or condition) can be misinterpreted would you need to do something else; in that case Syed's use of !!
does the trick.