0

This is just a very simple Vue code but I can't get it to work.

<input type="text" :class="'required-class' + custom_class" />

and my props is

props:{
    custom_class:{type:String}
      }

expected output:

<input type="text" class="required-class some-class-submitted" />

but returns:

<input type="text" class="NaN some-class-submitted" />

P.S I'm aware I can achieve this using the computed property, but is there any simpler solution without using it?

1 Answer 1

1

You cannot bind to the class property that way, instead do this: <input type="text" class="required-class" :class="[custom_class] " />

I recomend you read the documentation for binding classes and styles it is very well explained there https://v2.vuejs.org/v2/guide/class-and-style.html

Sign up to request clarification or add additional context in comments.

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.