首先说一下注意事项:在vue组件中设置时一定注意<style></style>中不能设置scoped属性,今天在项目中遇到的坑,尝试多次,给大分享一下,下边上代码:
<template>
<div class="about">
<el-table
:data="tableData"
border
stripe
highlight-current-row
table
:header-cell-style="{
background: '#eef1f6',
color: '#606266',
textAlign: 'center',
}"
style="width: 100%"
>
<el-table-column
type="selection"
width="55"
align="center"
></el-table-column>
<el-table-column prop="date" label="日期" width="180"> </el-table-column>
<el-table-column prop="name" label="姓名" width="180"> </el-table-column>
<el-table-column prop="address" label="地址"> </el-table-column>
</el-table>
</div>
</template>
<script>
export default {
data() {
return {
tableData: [
{
date: "2016-05-02",
name: "王小虎",
address: "上海市普陀区金沙江路 1518 弄",
},
{
date: "2016-05-04",
name: "王小虎",
address: "上海市普陀区金沙江路 1517 弄",
},
{
date: "2016-05-01",
name: "王小虎",
address: "上海市普陀区金沙江路 1519 弄",
},
{
date: "2016-05-03",
name: "王小虎",
address: "上海市普陀区金沙江路 1516 弄",
},
],
};
},
};
</script>
<style >
/* 用来设置当前页面element全局table的内间距 */
.el-table__row td {
padding: 0;
}
/* 用来设置当前页面element全局table 选中某行时的背景色*/
.el-table__body tr.current-row > td {
background-color: #78f709 !important;
/* color: #f19944; */ /* 设置文字颜色,可以选择不设置 */
}
/* 用来设置当前页面element全局table 鼠标移入某行时的背景色*/
.el-table--enable-row-hover .el-table__body tr:hover > td {
background-color: #f6d604 !important;
/* color: #f19944; */ /* 设置文字颜色,可以选择不设置 */
}
</style>
效果图: