el-table居中-序号-透明背景色等

el-table文本居中 

 整个表格和内容居中的方式:

<el-table
            :data="tableData"
            stripe
            style="width: 100%"
            :header-cell-style="{'text-align':'center'}"
            :cell-style="{ 'text-align': 'center' }"
          >
</el-table>

单个表格的内容居中:

<el-table-column label="xx" prop="xx" align="center">
</el-table-column>

el-table增加序号列

<el-table-column label="序号" width="100px" align="center">
     <template slot-scope="scope">
        {{ scope.$index + 1 }}
     </template>
</el-table-column>

el-table自定义背景颜色-字体样式等

将表格的背景色变成透明色: 

//一定要写在最外面!!!!

<style lang="scss" scoped>

  /*最外层透明*/
 ::v-deep .el-table,
 ::v-deep .el-table__expanded-cell {
    background-color: transparent !important;
}


/* 表格内背景颜色 */
 ::v-deep .el-table th,
 ::v-deep .el-table tr,
 ::v-deep .el-table td {
    background-color: transparent !important;
    border: 0; //去除表格
}
</style>

 修改表头和单元格内容的字体样式:

1.el-table修改表头样式:通过绑定header-cell-style属性进行实现
<el-table
    :data="tableData"
    stripe
    style="width: 100%"
    :header-cell-style="{ 'text-align': 'center',color: '#FFF' }">
</el-table>
2. el-table根据单元格内容动态修改单元格字体颜色

el-table添加属性:cell-style="cellStyle",methods里写该方法

cellStyle({ columnIndex }) {
      // 状态列字体颜色
      if (columnIndex === 3) {
        return "color : #99F17A";
      }
}

多选改为单选

 html:

<el-table
ref="myTable'
:data="tableData"
border
Aselection-change="setSelectRows">
    <el-table-column type="selection" width="50"></el-table-column>
</el-table>

js:

export default {
data(){
    return {
        tableData: [],
        selectRows:[]
    }
},
methods: {
//表格只能单选
setselectRows(selection) (
    this.selectRows = []
    if(selection.length==1){
    this.selectRows = [selection]
    }
    if (selection.length > 1) (
    this.$refs.myTable.clearSelection()
    this.$refs.myTable.toggleRowSelection(selection[selection.length - 1]
    this.selectRows = [selection[selection.length - 1]]
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值