1. <template>
  2. <el-table
  3. :data= "tableData"
  4. :row-style= "tableRowStyle"
  5. :header-cell-style= "tableHeaderColor">
  6. <el-table-column
  7. property= "name"
  8. label= "姓名"
  9. width= "120">
  10. </el-table-column>
  11. <el-table-column
  12. property= "age"
  13. label= "年龄"
  14. width= "120">
  15. </el-table-column>
  16. <el-table-column
  17. property= "sex"
  18. label= "性别"
  19. width= "120">
  20. </el-table-column>
  21. </el-table>
  22. </template>

 
 
  1. <script>
  2. export default {
  3. name: 'table',
  4. data() {
  5. return {
  6. tableData: [
  7. {
  8. name: 'Cindy',
  9. age: 20,
  10. sex: '女'
  11. },
  12. {
  13. name: 'Mila',
  14. age: 22,
  15. sex: '女'
  16. },
  17. {
  18. name: 'Bob',
  19. age: 23,
  20. sex: '男'
  21. }
  22. ]
  23. }
  24. },
  25. created() {},
  26. methods: {
  27. // 修改table tr行的背景色
  28. tableRowStyle({ row, rowIndex }) {
  29. return 'background-color: pink'
  30. },
  31. // 修改table header的背景色
  32. tableHeaderColor({ row, column, rowIndex, columnIndex }) {
  33. if (rowIndex === 0) {
  34. return 'background-color: lightblue;color: #fff;font-weight: 500;'
  35. }
  36. }
  37. }
  38. }
  39. < /script>

效果如下图:

Logo

前往低代码交流专区

更多推荐