项目中使用el组件进行快速开发,然而有的项目对组件有样式需求我们都是通过查找到设置样式的class用deep样式穿透进行样式修改,但如果要进行多种状态的判断来显示不同的样式,可以这样:
我以el的时间轴为例子,有进行的和没进行的要两个颜色,因此:
<el-timeline-item :class="{'yes': item.arrive,'no': !item.arrive}"
.yes {
::v-deep.el-timeline-item__node {
left: 308px;
width: 12px;
height: 12px;
background: none;
border: 4px #0659FB solid;
}
}
.no {
::v-deep.el-timeline-item__node {
left: 308px;
width: 12px;
height: 12px;
background: none;
border: 4px #75829B solid;
}
}
很简单,自定义class类嵌套样式穿透的原el组件class类就可以生效了