0

I need to change div class depend on variable value. The problem that value can have multiples values that should be evaluated as true for me.

isActive: "yes"

can be: "true", "agree". How to add switch of class and accept all this three variants: "yes", "true", "agree"?

https://jsfiddle.net/ogx1pt3y/

1 Answer 1

1

You can have a computed property where you return the correct class based on many conditions:

<p :class="paragraphClasses">{{ message }}</p>

new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue.js!',
    isActive: 'yes',
    shouldBeRed: true
  },
  computed: {
    paragraphClasses() {
      return this.isActive == 'yes' && this.shouldBeRed ? 'big' : 'small';
    }
  }
})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.