【问题标题】:Passing classes in with Slots to vue components使用 Slots 将类传入 vue 组件
【发布时间】:2019-10-04 13:55:00
【问题描述】:

我有一个 vue 组件

<Student></Student>

我想根据他们是本科生还是研究生来改变风格。

我知道我可以传入一个道具并使用该值来分配动态类或在计算道具中使用它。

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

但是我可以使用插槽来执行此操作并分配一个类,还是有更好的方法来使用道具来实现这一点?

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

我一直使用道具,但我觉得我可能会错过一个很好的插槽技术。

【问题讨论】:

  • 对于您的用例,props 似乎是一个不错的选择。为什么需要插槽?来自文档:using the &lt;slot&gt; element to serve as distribution outlets for content. Style is not content.
  • 我建议重写这个问题。澄清您的问题,以帮助人们了解您在寻找什么。

标签: class vuejs2 slots


【解决方案1】:

尝试添加类

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-06
    • 2019-08-12
    • 1970-01-01
    • 2017-10-11
    • 2021-01-06
    • 2018-04-23
    • 1970-01-01
    • 2021-07-30
    相关资源
    最近更新 更多