Modify element-ui style in vue

1. Add id or class to the component, then add a style, do not add scoped (Vue can have multiple styles), modify it directly in the component 2.
Use depth::v-deep to deeply modify the style of the component, you can write directly In the style to the scoped scope

Example: Modify the table background, etc.

<!-- 在element组件外加一层div,使其只在这个div内生效,防止改变全局 -->
<!-- 表头部分的样式需要利用组件提供的属性配合事件修改 -->
<div class="table-wrapper">
	<el-table id="out-table" v-loading="loading"
                 :cell-style="getRowClass"
                 :header-cell-style="getRowClass" :data="tableData" style="width: 100%;">
 </el-table>
</div>


methods:{

	// 修改element样式
            getRowClass({ row, column, rowIndex, columnIndex }) {
                return "background:transparent; border:none";
            }
}

//有scoped时,使用/deep/改变element样式
<style lang="less" scoped>
  //找到组件对应的类名利用deep修改样式
    .table-wrapper /deep/  .el-table, .el-table__expanded-cell {
        background-color: transparent;
    }

    .table-wrapper /deep/ .el-table tr {
        background-color: transparent!important;
    }
    .table-wrapper /deep/  .el-table--enable-row-transition .el-table__body td, .el-table .cell{
        background-color: transparent;
    }
    .table-wrapper /deep/  .el-table::before {
        height: 0;
    }
    .pager-box /deep/  .el-input__inner {
        background-color: transparent;
        color: #fff;
    }
</style>

//没有加spoced时,直接利用父级+所使用的组件类名修改即可
<style>
	.table-wrapper .el-table::before {
        height: 0;
    }
    .pager-box  .el-input__inner {
        background-color: transparent;
        color: #fff;
    }
</style>



Guess you like

Origin blog.csdn.net/weixin_42215897/article/details/109808534