1

I have a vue component

<Student></Student>

I want to change the style based on if they are an undergrad or postgrad.

I know I can pass in a prop and use this value to assign a dynamic class or use it in a computed prop.

<Student type="'postGrad'"></Student>

But can I do this with slots and assign a class or is there a better way to use props to achieve this?

<Student>
 <slot name="type">PostGrad/slot>
</Student>

I have always used props but feel I could be missing a good technique with slots.

TommyD
  • 913
  • 3
  • 17
  • 32
  • With your use case, props seems like a good option. Why would you need slots? From docs : `using the element to serve as distribution outlets for content.` Style is not content. – Sequoya May 17 '19 at 10:16
  • I would suggest to rewrite the question. Clarify your question to help people understand what you are looking for. – Adriano May 17 '19 at 10:33

1 Answers1

-1

Just try to add class

<Student class="myClass">
 <slot name="type">PostGrad/slot>
</Student>
Manu
  • 173
  • 2
  • 2
  • 12