el-table加背景色

 

 

<template>
  <div id="app">
    <el-table
      :data="tableData"
      border
      :header-cell-style="{
        background: '#fafafa',
        color: '#333',
        fontWeight: '600',
        fontSize: '14px',
      }"
      style="width: 541px"
      :row-style="TableRowStyle"
    >
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="age" label="年龄" width="180"> </el-table-column>
      <el-table-column prop="school" label="是否上学" width="180"> </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "app",
  data() {
    return {
      tableData: [
        {
          name: "孙悟空",
          age: 500,
          school: "上学中",
        },
        {
          name: "猪八戒",
          age: 88,
          school: "已辍学",
        },
        {
          name: "沙僧",
          age: 1000,
          school: "已辍学",
        },
        {
          name: "唐僧",
          age: 99999,
          school: "上学中",
        },
      ],
    };
  },
  methods: {
    // 当状态为 已辍学 的状态,加上背景色
    TableRowStyle({ row, rowIndex }) {
      // 注意,这里返回的是一个对象
      let rowBackground = {};
      if (row.school.includes("辍学") ) {
        rowBackground.background = "pink";
        return rowB<template>
  <div id="app">
    <el-table
      :data="tableData"
      border
      :header-cell-style="{
        background: '#fafafa',
        color: '#333',
        fontWeight: '600',
        fontSize: '14px',
      }"
      style="width: 541px"
      :row-style="TableRowStyle"
    >
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="age" label="年龄" width="180"> </el-table-column>
      <el-table-column prop="school" label="是否上学" width="180"> </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "app",
  data() {
    return {
      tableData: [
        {
          name: "孙悟空",
          age: 500,
          school: "上学中",
        },
        {
          name: "猪八戒",
          age: 88,
          school: "已辍学",
        },
        {
          name: "沙僧",
          age: 1000,
          school: "已辍学",
        },
        {
          name: "唐僧",
          age: 99999,
          school: "上学中",
        },
      ],
    };
  },
  methods: {
    // 当状态为 已辍学 的状态,加上背景色
    TableRowStyle({ row, rowIndex }) {
      // 注意,这里返回的是一个对象
      let rowBackground = {};
      if (row.school.includes("辍学") ) {
        rowBackground.background = "pink";
        return rowBackground;
      }
    },
  },
};
</script>ackground;
      }
    },
  },
};
</script>

 

上一篇:Python元组和字典


下一篇:mysql/mariadb 进阶知识之表设计和查询