vuejs
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Class and Style Bindings 87<br />
7.1.2 Array Syntax<br />
We can also apply a list of classes to an element using an array of classnames.<br />
1 <br />
Applying conditionally a class, can also be achieved with the use of inline if inside the array.<br />
1 <br />
Info<br />
Inline if is commonly referred to as the ternary operator, conditional operator, or<br />
ternary if.<br />
The conditional (ternary) operator is the only JavaScript operator that takes three operands.<br />
The syntax of ternary operator is condition ? expression1 : expression2. If condition<br />
is true, the operator returns the value of expression1, otherwise, it returns the value of<br />
expression2.<br />
Using inline if, the flipping colors example will look like:<br />
1 <br />
3 <br />
5 Flip color!<br />
6 <br />
7 <br />
1 new Vue({<br />
2 el: 'body',<br />
3 data: {<br />
4 color: true<br />
5 },<br />
6 methods: {<br />
7 flipColor: function() {<br />
8 this.color = !this.color;<br />
9 }<br />
10 }<br />
11 });