0

i'm use TailwindCss with vue

if i write component he has a prop like color:

<script setup>
defineProps({
    color: String // give me like: green
})
</script>

<div class="`bg-${color}-500`"> </div>

But when I see the result the color does not appear because Tailwind did not understand that this color was used

2 Answers 2

3

Adding on to Markiesch, Tailwind suggests not writing classes this way as they are not recognised by the purger on build, which means the class as you wrote it will most likely not work in production.

Tailwind docs state:

enter image description here

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

Comments

2

The class is not applying because the browser doesnt understand the syntax bg-${color}-500. Use the build-in Vue feature v-bind:class="" or using the shorthand : to make this work

<div :class="`bg-${color}-500`"> </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.