【发布时间】:2019-10-04 13:55:00
【问题描述】:
我有一个 vue 组件
<Student></Student>
我想根据他们是本科生还是研究生来改变风格。
我知道我可以传入一个道具并使用该值来分配动态类或在计算道具中使用它。
<Student type="'postGrad'"></Student>
但是我可以使用插槽来执行此操作并分配一个类,还是有更好的方法来使用道具来实现这一点?
<Student>
<slot name="type">PostGrad/slot>
</Student>
我一直使用道具,但我觉得我可能会错过一个很好的插槽技术。
【问题讨论】:
-
对于您的用例,props 似乎是一个不错的选择。为什么需要插槽?来自文档:
using the <slot> element to serve as distribution outlets for content.Style is not content. -
我建议重写这个问题。澄清您的问题,以帮助人们了解您在寻找什么。