I am using vuejs and I would like to switch my class depending on the data value. If its a negative number, i would like to use the .neg class and when its a positive number, i would like to use the .pos class.
Everything is working, except for adding the class.
The data looks like this: 5, -7, 8, -2, 4, -9 ect
myArray: function () {
var test = [5, -7, 8, -2, 4, -9];
return test;
},
<div v-for="data in myArray">
<div v-bind:class="{'neg': data < 0, 'pos': data > 0}"></div>
<div id="my">{{ data }}</div>
</div>
.pos {background-color: green;}
.neg {background-color: red;}
Any help would be appropriated.
data in myArray()? Also, I wouldn't keep re-using the "my"idin the loop. You'll end up with duplicatesneg/posclassed elements have no content?