实际项目对 Element Plus 做了大量定制(全局主题 SCSS、表格精简边框变体)。新手常遇到:

复制代码.ep-table td {
border-right: none; /* 写了但没效果 */
}
常见原因:
scoped 加了 [data-v-xxx],选不到 EP 内部 DOMep- 前缀(非默认 el-)EP 2.x 大量组件支持 CSS Variables:
复制代码.ep-table {
--ep-table-header-bg-color: #fafafa;
--ep-table-border-color: #e8e8e8;
--ep-table-row-hover-bg-color: #fafafa;
}
改变量 = 全局换肤,升级 EP 版本时 breakage 最小。
:deep() 穿透 Scoped 复制代码<style scoped lang="scss">
.table-clean {
:deep(td.ep-table__cell) {
border-right: none !important;
}
}
</style>
:deep() 让 scoped 编译后仍能选中子组件内部节点。
项目把 Tabs、Dialog、Checkbox 等放在 styles/element/index.scss,业务组件只加 class:
复制代码<tabs v-model="activeTab" class="h-tabs--segment">
设计稿要求:去掉单元格右边框,表头用伪元素做短分隔线,左侧固定列始终有分隔线。
Element Plus 只在特定滚动状态下给固定列加 border-right:
复制代码<div class="ep-table is-scrolling-middle">
<td class="ep-table-fixed-column--left is-last-column">
错误写法(选不到):
复制代码.table-clean.is-scrolling-middle td { ... } /* is-scrolling 在 .ep-table 上 */
正确写法:
复制代码.table-clean {
:deep(.ep-table.is-scrolling-none),
:deep(.ep-table.is-scrolling-left),
:deep(.ep-table.is-scrolling-right),
:deep(.ep-table.is-scrolling-middle) {
td.ep-table-fixed-column--left.is-last-column,
th.ep-table-fixed-column--left.is-last-column {
border-right: 1px solid var(--ep-table-border-color) !important;
}
}
}
难点:必须在 DevTools 里看清状态类挂在哪一层 DOM,再写选择器。
EP 自带 active-bar,设计要宽度跟随文字的指示线。方案:
.ep-tabs__active-bar--tabs-bar-x、--tabs-bar-widthoffsetLeft/offsetWidth样式与逻辑分离,避免硬编码 left 像素。
el-dialog 默认 append-to-body,DOM 挂在 body 下,不在组件 scoped 树内:
复制代码// Dialog 封装 内
:global(.app-dialog:not(.is-fullscreen) .ep-dialog__body) {
flex: 1;
min-height: 0;
}
或用 popper-class / modal-class / body-class 传入包装类名。
ep-table__cell)scoped 验证是否是穿透问题!important,优先变量 + 层级| 场景 | 推荐 |
|---|---|
| 换色、圆角、间距 | CSS Variables |
| 组件内改 EP 结构 | :deep() + 包装 class |
| Dialog/Teleport 节点 | :global() 或 EP 的 *-class props |
| 表格滚动/固定列 | 查清 is-scrolling-* 挂载层级 |
以上难点来自真实 B 端项目工程实践。若对你有帮助,欢迎 点赞、收藏,有问题评论区交流。
发布到掘金时建议:
专栏「前端难点实战」: