0

In my view I have the following conditional class:

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

and in my component I have the following:

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

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

    return positive
}

...but then my computed class shows as:

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

regardless of the result of positivity(). What am I doing wrong?

1 Answer 1

1

You can do :

v-bind:class="positivity"

or :

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

and

positivity: function() {
    return typeof this.transaction.weeks != "undefined";
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Not sure why I included the curly braces

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.