2017-04-03 28 views
0

计算值在我看来,我有以下条件类:Vue.js:为

<td class="text-center" v-bind:class="{ positivity }"></td> 

,并在我的组件我有以下几点:

positivity: function() { 
    var type = typeof this.transaction.weeks != "undefined" 
    var positive = 'green-bold' 

    if (type) { 
     positive = 'red-bold' 
    } 

    return positive 
} 

...但后来我计算类显示为:

<td class="text-center positivity"></td> 

不管结果为positivity()。我究竟做错了什么?

回答

1

你可以这样做:

v-bind:class="positivity" 

或:

v-bind:class="{ 'green-bold': !positivity, 'red-bold': positivity }" 

positivity: function() { 
    return typeof this.transaction.weeks != "undefined"; 
} 
+0

谢谢!不知道为什么我包括大括号 –