Since both values need to be true in order for the expression to be true, if the first is false there is no point in checking what the second one is, since we already know the expression evaluates to false. In Javascript, the & (AND) operator will short-circuit if the first value is false. Here we have the variable useTheme which is a boolean, and theme is the value of the theme class. When useTheme is true, it will set the class to whatever the value of theme is. This is how you add dynamic classes in Vue. There is a cool trick using the logical & (AND) that allows us to conditionally apply a class: How can we toggle this behaviour and make it conditional? Guard Expressions Learning more about conditional class bindings!īut this will always apply the value of className as a class to our span tag. Normally we shorten the binding syntax by removing v-bind, and we're left with just this: If the value of className is blue-text, it will add the class. Learning about conditional class bindings! To refresh your memory, to bind a variable to a prop, class, or style, we use this syntax:
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |