I'd like to learn what is the best way to conditionally render an HTML attribute in Vue.js. For example, add data-toggle="tooltip" if there is a tooltip message for current instance.
The code I have now:
<span
:data-toggle="!!col.col_spec.tooltip ? 'tooltip' : ''"
:title="col.col_spec.tooltip"
>
{{ col.col_spec.title }}
</span>
Though, I don't like the 2nd line much… Even if I use computed property here, I'd prefer not to have data-toggle attribute at all, when there is no tooltip to display.
requiredindeed is a boolean attribute, you can not pass afalsevalue to it. "The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value." The only way to use it is to either have it in the DOM, or don't.