Answer the question
In order to leave comments, you need to log in
How to organize component customization?
There is, for example, the Parent.vue component, which renders other components in itself:
<div class="parent">
<Child1 class="child1">
<Child2 class="child2">
</Child2>
</Child1>
</div>
.child2 {
color: red;
}
<div class="parent">
<Child1 class="child1">
<Child2 :class="{child2: true, child2_color_red: childRedColor}">
</Child2>
</Child1>
</div>
props: {childRedColor: Boolean}
//
<Parent :childRedColor="true" />
<div class="parent">
<Child1 class="child1">
<Child2 :class="'child2' + child2Classes.join(' ')">
</Child2>
</Child1>
</div>
props: {child2Classes: Array}
//
<Parent :child2Classes="['child2_color_red']" />
Answer the question
In order to leave comments, you need to log in
And who chooses the color? parent component? Or someone above?
If the second case, then, I suppose, props in any form, or inject.
Otherwise, the question is: The text can only be red? Or is there a possibility that a different color will be needed? If the second option, then I think a custom property would be appropriate:
<template>
<div class="parent">
<Child1 class="child1">
<Child2 class="child2" :style="'--text-color: ' + textColor">
</Child2>
</Child1>
</div>
</template>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question