Vue 3:设计命名槽的样式
所以我浏览了 stackoverflow 和 Vue 3 中的文档,但找不到我要找的东西。
我正在尝试找到一种方法来定位命名插槽,渗透该插槽内的作用域元素,并覆盖其子样式之一。我假设我需要 ::slotted 选择器和 :deep 选择器来完成此任务。有谁知道该怎么做?
这是我试图解决的情况的示例(LayoutContainer 组件):
<section>
<slot name="text"></slot>
<slot></slot>
<slot name="sidebar"></slot>
</section>
将进入“文本”槽的组件(Eyebrow 组件):
<section class="eyebrow-container">
<h1>{{title}}</h1>
<h6>{{description"}}</h6>
</section>
页面组件上代码的完整视图:
<LayoutContainer>
<template #text>
<Eyebrow :title='test' :description="this is a description"></Eyebrow>
</template>
<PageBody></PageBody>
<template #sidebar>
<PageSideBar></PageSideBar>
</template>
</LayoutContainer>
我尝试过的解决方案SCSS 没有成功:
::slotted(h6) { color: red }
::slotted(text){
:deep(.eyebrow-container) {
h6 { color: red; }
}
}
::slotted(text) {
:deep(h6) { color: red; }
}
还有其他一些我现在已经忘记了。
有谁知道如何从页面组件的 SCSS 获取眉毛组件内的 h6 标签?
So I've looked through stackoverflow and the documentation in Vue 3 but can't quite find what I'm looking for.
I'm trying to find a way to target a named slot, penetrate the scoped element within that slot, and override one of its children's styles. I assume I need the ::slotted selector and the :deep selector for this mission. Does anyone know how to do this?
Here is an example of the situation I am trying to solve for (LayoutContainer Component):
<section>
<slot name="text"></slot>
<slot></slot>
<slot name="sidebar"></slot>
</section>
the component that will go into the "text" slot (Eyebrow Component):
<section class="eyebrow-container">
<h1>{{title}}</h1>
<h6>{{description"}}</h6>
</section>
a completed view of the code on a page component:
<LayoutContainer>
<template #text>
<Eyebrow :title='test' :description="this is a description"></Eyebrow>
</template>
<PageBody></PageBody>
<template #sidebar>
<PageSideBar></PageSideBar>
</template>
</LayoutContainer>
Solutions I have tried in SCSS with no success:
::slotted(h6) { color: red }
::slotted(text){
:deep(.eyebrow-container) {
h6 { color: red; }
}
}
::slotted(text) {
:deep(h6) { color: red; }
}
and a few others I have forgotten at this point.
Does anyone have any ideas on how to get to the h6 tag inside of the Eyebrow Component from the Page Component's SCSS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此您不需要使用
:slotted
。您只需使用 :deep 选择器观看直播
如果您想知道如何使用
:slotted
那么在您的情况下,它将在LayoutContainer
组件中使用,尝试设置父组件传入的样式。作用域样式和样式子组件如果您使用多根节点组件,来自父级的组件不会像您想象的那样工作。
因此,如果您使用多根节点组件并且
:deep
不起作用,查看我的其他答案So you don't need to use
:slotted
. You can simply use the :deep selectorSee it live
If you are wondering how to use
:slotted
then in your case it would be used inLayoutContainer
component trying to style what the parent component passes in.Scoped styling and styling child components from a parent don't work as you might think if you use multi-root node components.
So if you use mutli-root node component and
:deep
doesn't work, See my other answer