So, I was watching vue2 tutorial, when I found this piece of code which I don't understand why and how it really works.
Here is a style:
<style type="text/css">
.is-loading { background: red }
</style>
and the html:
<div id="root">
<button :class="{ 'is-loading': isLoading }" @click="toggleClass"> Toggle Me</button>
</div>
and vue code:
new Vue({
el: '#root',
data: {
isLocading: false
},
methods: {
toggleClass: function(){
this.isLoading = !this.isLoading;
}
}
});
Now, this code toggles the class name for the button when clicked, but what I don't understand is the { 'is-loading': isLoading } part, which does not seem to be a ternary operator.
What exactly is it saying? the class name is already mentioned first as is-loading but the variable appears after it.
Shouldn't this look like { variable ? 'class' ? 'no-class' } in other words, shouldn't the variable appear first, then the class?
isLoading === truebut, why does it appear in the order it does?if-true : 'somevalue'but in this case it appears the other way around likesomvalue : if-true@Fals