封装el-table

封装组件

<template>
  <!-- 表格分页 -->
  <div class="table_box">
    <el-table :data="tableData" style="width: 100%" :border="border" :header-cell-style="{background:'#f6f9ff'}" :cell-class-name="cellStyle">
      <el-table-column type="index" :index="indexMethod" align="center" label="序号" width="65" v-if="showIndex">
      </el-table-column>
      <el-table-column v-for="(item, index) in columns" :key="index" :align="item.align" :prop="item.prop" :label="item.label" :fixed="item.fixed" :width="item.width" :sortable="item.sortable" :min-width="item.minWidth" :show-overflow-tooltip="item.showOverflowTooltip">
        <template slot-scope="scope">
          <slot v-if="item.slot" :row="scope.row" :name="item.slot"></slot>
          <span v-else>{{ scope.row[item.prop] || "--" }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination layout="total, sizes, prev, pager, next, jumper" :current-page="currentPage" :page-size="pageSize" @current-change="handleCurrentChange" @size-change="handleSizeChange" :total="total > 10000 ? 10000 : total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  props: {
    border: {
      type: Boolean,
      default: false,
    },
    showIndex: {
      type: Boolean,
      default: false,
    },
    tableData: {
      type: Array,
      default: [],
    },
    columns: {
      type: Array,
      default: [],
    },
    total: {
      type: Number,
      default: 0,
    },
    currentPage: {
      type: Number,
      default: 1,
    },
    pageSize: {
      type: Number,
      default: 10,
    },
    cellStyle: {
      type: Function,
    },
  },
  data() {
    return {};
  },
  created() {},
  mounted() {
    this.cellStyle;
  },
  methods: {
    handleSizeChange(val) {
      this.$emit("changeSize", val);
    },
    handleCurrentChange(val) {
      this.$emit("changeCurrent", val);
    },
    //表单选择全选
    handleSelectionChange(val) {
      this.$emit("handleSelectionChange", val);
    },
    indexMethod(index) {
      return index + 1 + (this.currentPage - 1) * 10;
    },
  },
};
</script>

<style lang="scss" scoped>
.el-pagination {
  padding: 10px;
  text-align: right;
  background: #fff;
}
// .table_box {
//   /deep/.el-table__header-wrapper {
//     .tableHeader {
//       th {
//         background-color: #f6f9ff !important;
//       }
//       .el-table_1_column_1 {
//         background-color: #f6f9ff !important;
//       }
//     }
//   }
//   // .tableHeader {
//   //   border: 1px solid #f40;
//   //   background-color: #f6f9ff !important;
//   // }
// }
</style>

使用

1.引入组件

import Table from "@/components/Table/index.vue";

2.注册组件

components: {
    Table,
  },

3.配置表头数据

data() {
    return {
      columns: [
        {
          prop: "userId",
          label: "用户ID",
          minWidth: 70,
          showOverflowTooltip: true,
        },
        {
          prop: "username",
          label: "用户账号",
          minWidth: 100,
          showOverflowTooltip: true,
        },
        {
          prop: "authUserName",
          label: "认证姓名",
          minWidth: 80,
          showOverflowTooltip: true,
        },
        {
          prop: "authIdNo",
          label: "认证身份证号",
          minWidth: 140,
          showOverflowTooltip: true,
        },
        {
          prop: "authMobile",
          label: "认证手机号码",
          minWidth: 100,
          showOverflowTooltip: true,
        },
        {
          prop: "authBankNo",
          label: "认证银行卡号",
          minWidth: 140,
          showOverflowTooltip: true,
        },
        {
          slot: "personAuthResult",
          label: "认证状态",
          minWidth: 80,
          showOverflowTooltip: true,
        },
        {
          prop: "registerTime",
          label: "注册时间",
          minWidth: 120,
          showOverflowTooltip: true,
        },
        {
          slot: "lockFlag",
          label: "账号状态",
          minWidth: 80,
          showOverflowTooltip: true,
        },
        {
          slot: "action",
          label: "操作",
          minWidth: 130,
        },
      ],
      tableData: [],
      total: 0,
      currentPage: 1,
      pageSize: 10,
    };
  },

4.配置组件

<div class="tableWrap">
      <Table :tableData="tableData" :columns="columns" :cellStyle="cellStyle" :total="total" :currentPage="currentPage" :pageSize="pageSize" @changeSize="handleSizeChange" @changeCurrent="handleCurrentChange">
        <template slot="personAuthResult" slot-scope="scope">
          {{ personAuthResultObj[scope.row.personAuthResult] }}
        </template>
        <template slot="lockFlag" slot-scope="scope">
          <el-switch v-model="scope.row.lockFlag" active-color="#13ce66" inactive-color="#ff4949" active-value="0" inactive-value="1" @change="changelockFlag(scope.row)"></el-switch>
        </template>
        <template slot="action" slot-scope="scope">
          <el-button type="text" @click="particular(scope.row)">详情</el-button>
        </template>
      </Table>
    </div>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值