【问题标题】:Vue.js: Computed value for classVue.js:类的计算值
【发布时间】:2017-04-03 14:21:54
【问题描述】:

在我看来,我有以下条件类:

<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() 的结果如何。我做错了什么?

【问题讨论】:

    标签: vue.js vuejs2 vue-component


    【解决方案1】:

    你可以这样做:

    v-bind:class="positivity"
    

    或:

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

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

    【讨论】:

    • 谢谢!不知道为什么我包括花括号
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 2016-08-09
    • 2017-09-24
    • 2015-05-28
    • 2019-05-23
    • 2017-08-26
    • 1970-01-01
    相关资源
    最近更新 更多