2

How do I dynamically concat a text with vuejs 2

Here is what I have now:

<span class="label" :class="label-{{account.Segment}}">{{account.Segment}}</span>

account.Segment == "ABC"

What I need rendered is that

<span class="label label-ABC">ABC</span>

2 Answers 2

16

Here is one possible way.

<span class="label" :class="'label-' + account.Segment">{{account.Segment}}</span>
Sign up to request clarification or add additional context in comments.

Comments

0

You can add more classes using an array of string

computed: {
  classNames() {
    // add more logic here
    let classNames = ['label'];
    classNames.push(`label-${this.contextType}`);
    return classNames;
  },
},

and then you can use it like this

<div :class="classNames">
...
</div>

Comments

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.